Search in sources :

Example 76 with PackageManager

use of android.content.pm.PackageManager in project platform_frameworks_base by android.

the class SystemImpl method uninstallAndDisablePackageForAllUsers.

@Override
public void uninstallAndDisablePackageForAllUsers(Context context, String packageName) {
    enablePackageForAllUsers(context, packageName, false);
    try {
        PackageManager pm = AppGlobals.getInitialApplication().getPackageManager();
        ApplicationInfo applicationInfo = pm.getApplicationInfo(packageName, 0);
        if (applicationInfo != null && applicationInfo.isUpdatedSystemApp()) {
            pm.deletePackage(packageName, new IPackageDeleteObserver.Stub() {

                public void packageDeleted(String packageName, int returnCode) {
                    enablePackageForAllUsers(context, packageName, false);
                }
            }, PackageManager.DELETE_SYSTEM_APP | PackageManager.DELETE_ALL_USERS);
        }
    } catch (NameNotFoundException e) {
    }
}
Also used : IPackageDeleteObserver(android.content.pm.IPackageDeleteObserver) PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ApplicationInfo(android.content.pm.ApplicationInfo)

Example 77 with PackageManager

use of android.content.pm.PackageManager in project platform_frameworks_base by android.

the class GrantCredentialsPermissionActivity method onCreate.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.grant_credentials_permission);
    setTitle(R.string.grant_permissions_header_text);
    mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final Bundle extras = getIntent().getExtras();
    if (extras == null) {
        // we were somehow started with bad parameters. abort the activity.
        setResult(Activity.RESULT_CANCELED);
        finish();
        return;
    }
    // Grant 'account'/'type' to mUID
    mAccount = extras.getParcelable(EXTRAS_ACCOUNT);
    mAuthTokenType = extras.getString(EXTRAS_AUTH_TOKEN_TYPE);
    mUid = extras.getInt(EXTRAS_REQUESTING_UID);
    final PackageManager pm = getPackageManager();
    final String[] packages = pm.getPackagesForUid(mUid);
    if (mAccount == null || mAuthTokenType == null || packages == null) {
        // we were somehow started with bad parameters. abort the activity.
        setResult(Activity.RESULT_CANCELED);
        finish();
        return;
    }
    String accountTypeLabel;
    try {
        accountTypeLabel = getAccountLabel(mAccount);
    } catch (IllegalArgumentException e) {
        // label or resource was missing. abort the activity.
        setResult(Activity.RESULT_CANCELED);
        finish();
        return;
    }
    final TextView authTokenTypeView = (TextView) findViewById(R.id.authtoken_type);
    authTokenTypeView.setVisibility(View.GONE);
    final AccountManagerCallback<String> callback = new AccountManagerCallback<String>() {

        public void run(AccountManagerFuture<String> future) {
            try {
                final String authTokenLabel = future.getResult();
                if (!TextUtils.isEmpty(authTokenLabel)) {
                    runOnUiThread(new Runnable() {

                        public void run() {
                            if (!isFinishing()) {
                                authTokenTypeView.setText(authTokenLabel);
                                authTokenTypeView.setVisibility(View.VISIBLE);
                            }
                        }
                    });
                }
            } catch (OperationCanceledException e) {
            } catch (IOException e) {
            } catch (AuthenticatorException e) {
            }
        }
    };
    if (!AccountManager.ACCOUNT_ACCESS_TOKEN_TYPE.equals(mAuthTokenType)) {
        AccountManager.get(this).getAuthTokenLabel(mAccount.type, mAuthTokenType, callback, null);
    }
    findViewById(R.id.allow_button).setOnClickListener(this);
    findViewById(R.id.deny_button).setOnClickListener(this);
    LinearLayout packagesListView = (LinearLayout) findViewById(R.id.packages_list);
    for (String pkg : packages) {
        String packageLabel;
        try {
            packageLabel = pm.getApplicationLabel(pm.getApplicationInfo(pkg, 0)).toString();
        } catch (PackageManager.NameNotFoundException e) {
            packageLabel = pkg;
        }
        packagesListView.addView(newPackageView(packageLabel));
    }
    ((TextView) findViewById(R.id.account_name)).setText(mAccount.name);
    ((TextView) findViewById(R.id.account_type)).setText(accountTypeLabel);
}
Also used : Bundle(android.os.Bundle) IOException(java.io.IOException) PackageManager(android.content.pm.PackageManager) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Example 78 with PackageManager

use of android.content.pm.PackageManager in project newsrob by marianokamp.

the class EntryManager method maintainBootReceiverState.

public void maintainBootReceiverState() {
    final ComponentName cName = new ComponentName(ctx, BootReceiver.class);
    final PackageManager pm = ctx.getPackageManager();
    final int newComponentState = isAutoSyncEnabled() ? PackageManager.COMPONENT_ENABLED_STATE_DEFAULT : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    if (pm.getComponentEnabledSetting(cName) != newComponentState) {
        Log.d(TAG, "Setting new component enabled state on BootReceiver: " + isAutoSyncEnabled());
        pm.setComponentEnabledSetting(cName, newComponentState, PackageManager.DONT_KILL_APP);
    }
    PL.log("EntryManager.maintainBootReceiverState(): Component enabled=" + pm.getComponentEnabledSetting(cName), ctx);
}
Also used : PackageManager(android.content.pm.PackageManager) ComponentName(android.content.ComponentName)

Example 79 with PackageManager

use of android.content.pm.PackageManager in project newsrob by marianokamp.

the class EntryManager method maintainBootReceiverStateAndScheduler.

public void maintainBootReceiverStateAndScheduler() {
    final ComponentName cName = new ComponentName(ctx, BootReceiver.class);
    final PackageManager pm = ctx.getPackageManager();
    final int newComponentState = isAutoSyncEnabled() ? PackageManager.COMPONENT_ENABLED_STATE_DEFAULT : PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    if (pm.getComponentEnabledSetting(cName) != newComponentState) {
        Log.d(TAG, "Setting new component enabled state on BootReceiver: " + isAutoSyncEnabled());
        pm.setComponentEnabledSetting(cName, newComponentState, PackageManager.DONT_KILL_APP);
    }
    PL.log("EntryManager.maintainBootReceiverState(): Component enabled=" + pm.getComponentEnabledSetting(cName), ctx);
    scheduler.ensureSchedulingIsEnabled();
}
Also used : PackageManager(android.content.pm.PackageManager) ComponentName(android.content.ComponentName)

Example 80 with PackageManager

use of android.content.pm.PackageManager in project AndroidPerformanceMonitor by markzhai.

the class BlockCanary method setEnabledBlocking.

private static void setEnabledBlocking(Context appContext, Class<?> componentClass, boolean enabled) {
    ComponentName component = new ComponentName(appContext, componentClass);
    PackageManager packageManager = appContext.getPackageManager();
    int newState = enabled ? COMPONENT_ENABLED_STATE_ENABLED : COMPONENT_ENABLED_STATE_DISABLED;
    // Blocks on IPC.
    packageManager.setComponentEnabledSetting(component, newState, DONT_KILL_APP);
}
Also used : PackageManager(android.content.pm.PackageManager) ComponentName(android.content.ComponentName)

Aggregations

PackageManager (android.content.pm.PackageManager)1482 Intent (android.content.Intent)505 ResolveInfo (android.content.pm.ResolveInfo)460 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)353 PackageInfo (android.content.pm.PackageInfo)270 ApplicationInfo (android.content.pm.ApplicationInfo)253 ComponentName (android.content.ComponentName)241 ArrayList (java.util.ArrayList)158 ActivityInfo (android.content.pm.ActivityInfo)140 IOException (java.io.IOException)127 RemoteException (android.os.RemoteException)105 Drawable (android.graphics.drawable.Drawable)94 IPackageManager (android.content.pm.IPackageManager)93 Resources (android.content.res.Resources)91 PendingIntent (android.app.PendingIntent)75 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)69 Context (android.content.Context)68 Bundle (android.os.Bundle)60 HashMap (java.util.HashMap)55 ServiceInfo (android.content.pm.ServiceInfo)48