protected void onCreate(Bundle icicle) { Uri packageUri; super.onCreate(icicle); this.mPm = getPackageManager(); this.mInstaller = this.mPm.getPackageInstaller(); this.mUserManager = (UserManager) getSystemService("user"); Intent intent = getIntent(); this.mOriginatingUid = getOriginatingUid(intent); if ("android.content.pm.action.CONFIRM_PERMISSIONS".equals(intent.getAction())) { int sessionId = intent.getIntExtra("android.content.pm.extra.SESSION_ID", -1); PackageInstaller.SessionInfo info = this.mInstaller.getSessionInfo(sessionId); if (info == null || !info.sealed || info.resolvedBaseCodePath == null) { Log.w("PackageInstaller", "Session " + this.mSessionId + " in funky state; ignoring"); finish(); return; } this.mSessionId = sessionId; packageUri = Uri.fromFile(new File(info.resolvedBaseCodePath)); this.mOriginatingURI = null; this.mReferrerURI = null; } else { this.mSessionId = -1; packageUri = intent.getData(); this.mOriginatingURI = (Uri) intent.getParcelableExtra("android.intent.extra.ORIGINATING_URI"); this.mReferrerURI = (Uri) intent.getParcelableExtra("android.intent.extra.REFERRER"); } if (packageUri == null) { Log.w("PackageInstaller", "Unspecified source"); setPmResult(-3); finish(); } else if (DeviceUtils.isWear(this)) { showDialogInner(7); } else { setContentView(R.layout.install_start); this.mInstallConfirm = findViewById(R.id.install_confirm_panel); this.mInstallConfirm.setVisibility(4); this.mOk = (Button) findViewById(R.id.ok_button); this.mCancel = (Button) findViewById(R.id.cancel_button); this.mOk.setOnClickListener(this); this.mCancel.setOnClickListener(this); boolean wasSetUp = processPackageUri(packageUri); if (!wasSetUp) { return; } checkIfAllowedAndInitiateInstall(false); } }
时间: 2024-02-14 18:32:49 浏览: 130
源码详解Android中View.post()用法
这段代码是关于 Android Package Installer 的,它是用来安装 Android 应用程序的。在 onCreate() 方法中,首先获取了 PackageManager 和 PackageInstaller 对象,然后根据传入的 Intent 对象的不同 action 和数据,决定进行新的安装还是确认已有权限。如果是新的安装,则根据传入的 packageUri 进行安装前的相关检查和确认。最后,根据检查的结果,调用 checkIfAllowedAndInitiateInstall() 方法来开始安装应用程序。
阅读全文