Android修改PackageInstaller自动安装指定应用

— a/packages/apps/PackageInstaller/src/com/android/packageinstaller/InstallAppProgress.java

+++ b/packages/apps/PackageInstaller/src/com/android/packageinstaller/InstallAppProgress.java

@@ -58,6 +58,7 @@ import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

import java.util.List;

+import android.content.ComponentName;

/**

  • This activity corresponds to a download progress screen that is displayed

@@ -101,6 +102,29 @@ public class InstallAppProgress extends Activity implements View.OnClickListener

clearCachedApkIfNeededAndFinish();

return;

}

  •                if (getIntent().getBooleanExtra("AutoInstall", false) && msg.arg1 == PackageManager.INSTALL_SUCCEEDED) {
    
  •                    Intent  mIntent = getPackageManager().getLaunchIntentForPackage(
    
  •                            mAppInfo.packageName);
    
  •                    boolean enabled = false;
    
  •                    if(mIntent != null) {
    
  •                        List<ResolveInfo> list = getPackageManager().
    
  •                                queryIntentActivities(mIntent, 0);
    
  •                        if (list != null && list.size() > 0) {
    
  •                            enabled = true;
    
  •                        }
    
  •                    }
    
  •                    if (enabled && "com.antutu.benchmark.full".equals(mAppInfo.packageName)) {//如果自动安装的apk是antutufull(3dTest),则>安装完成后自动启动测试
    
  •                        Intent intent = new Intent("com.antutu.benchmark.full.MAROONED_RUN");
    
  •                        intent.setFlags(335544320);
    
  •                        intent.setComponent(new ComponentName("com.antutu.benchmark.full", "com.antutu.benchmark.full.UnityPlayerActivity"));
    
  •                        intent.putExtra("uid", "8939");
    
  •                        startActivity(intent);
    
  •                        //startActivity(mIntent);
    
  •                    }
    
  •                     finish();
    
  •                    return;
    
  •                }
    

// Update the status text

mProgressBar.setVisibility(View.GONE);

// Show the ok button

diff --git a/packages/apps/PackageInstaller/src/com/android/packageinstaller/PackageInstallerActivity.java b/packages/apps/PackageInstaller/src/com/android/packageinstaller/Pack

index de68582…b85b767 100644

— a/packages/apps/PackageInstaller/src/com/android/packageinstaller/PackageInstallerActivity.java

+++ b/packages/apps/PackageInstaller/src/com/android/packageinstaller/PackageInstallerActivity.java

@@ -120,6 +120,35 @@ public class PackageInstallerActivity extends Activity implements OnCancelListen

private static final int DLG_NOT_SUPPORTED_ON_WEAR = DLG_BASE + 7;

private void startInstallConfirm() {

  •      if(mAutoInstall)
    
  •    {
    
  •                Intent newIntent = new Intent();
    
  •                newIntent.putExtra(PackageUtil.INTENT_ATTR_APPLICATION_INFO,
    
  •                                                 mPkgInfo.applicationInfo);
    
  •                newIntent.setData(mPackageURI);
    
  •                newIntent.setClass(this, InstallAppProgress.class);
    
  •                String installerPackageName = getIntent().getStringExtra(Intent.EXTRA_INSTALLER_PACKAGE_NAME);
    
  •                if (mOriginatingURI != null) {
    
  •                    newIntent.putExtra(Intent.EXTRA_ORIGINATING_URI, mOriginatingURI);
    
  •                }
    
  •                if (mReferrerURI != null) {
    
  •                    newIntent.putExtra(Intent.EXTRA_REFERRER, mReferrerURI);
    
  •                }
    
  •                if (mOriginatingUid != VerificationParams.NO_UID) {
    
  •                    newIntent.putExtra(Intent.EXTRA_ORIGINATING_UID, mOriginatingUid);
    
  •                }
    
  •                if (installerPackageName != null) {
    
  •                    newIntent.putExtra(Intent.EXTRA_INSTALLER_PACKAGE_NAME,installerPackageName);
    
  •                }
    
  •                if (getIntent().getBooleanExtra(Intent.EXTRA_RETURN_RESULT, false)) {
    
  •                    newIntent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
    
  •                    newIntent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
    
  •                }
    
  •                newIntent.putExtra("AutoInstall", true);
    
  •                if(localLOGV) Log.i(TAG, "downloaded app uri="+mPackageURI);
    

设计模式学习笔记

设计模式系列学习视频

参考docs.qq.com/doc/DSkNLaERkbnFoS0ZF
模式学习笔记

[外链图片转存中…(img-L6Ik4Bux-1724497248710)]

设计模式系列学习视频

[外链图片转存中…(img-cvPdIDQp-1724497248711)]

参考docs.qq.com/doc/DSkNLaERkbnFoS0ZF

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值