Search in sources :

Example 51 with ActivityInfo

use of android.content.pm.ActivityInfo in project android_frameworks_base by ResurrectionRemix.

the class SearchDialog method updateSearchAppIcon.

private void updateSearchAppIcon() {
    PackageManager pm = getContext().getPackageManager();
    Drawable icon;
    try {
        ActivityInfo info = pm.getActivityInfo(mLaunchComponent, 0);
        icon = pm.getApplicationIcon(info.applicationInfo);
        if (DBG)
            Log.d(LOG_TAG, "Using app-specific icon");
    } catch (NameNotFoundException e) {
        icon = pm.getDefaultActivityIcon();
        Log.w(LOG_TAG, mLaunchComponent + " not found, using generic app icon");
    }
    mAppIcon.setImageDrawable(icon);
    mAppIcon.setVisibility(View.VISIBLE);
    mSearchPlate.setPadding(SEARCH_PLATE_LEFT_PADDING_NON_GLOBAL, mSearchPlate.getPaddingTop(), mSearchPlate.getPaddingRight(), mSearchPlate.getPaddingBottom());
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Drawable(android.graphics.drawable.Drawable)

Example 52 with ActivityInfo

use of android.content.pm.ActivityInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DeviceAdminAdd method onCreate.

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    mHandler = new Handler(getMainLooper());
    mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    mAppOps = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE);
    PackageManager packageManager = getPackageManager();
    if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
        Log.w(TAG, "Cannot start ADD_DEVICE_ADMIN as a new task");
        finish();
        return;
    }
    mIsCalledFromSupportDialog = getIntent().getBooleanExtra(EXTRA_CALLED_FROM_SUPPORT_DIALOG, false);
    String action = getIntent().getAction();
    ComponentName who = (ComponentName) getIntent().getParcelableExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN);
    if (who == null) {
        String packageName = getIntent().getStringExtra(EXTRA_DEVICE_ADMIN_PACKAGE_NAME);
        for (ComponentName component : mDPM.getActiveAdmins()) {
            if (component.getPackageName().equals(packageName)) {
                who = component;
                mUninstalling = true;
                break;
            }
        }
        if (who == null) {
            Log.w(TAG, "No component specified in " + action);
            finish();
            return;
        }
    }
    if (action != null && action.equals(DevicePolicyManager.ACTION_SET_PROFILE_OWNER)) {
        setResult(RESULT_CANCELED);
        setFinishOnTouchOutside(true);
        mAddingProfileOwner = true;
        mProfileOwnerName = getIntent().getStringExtra(DevicePolicyManager.EXTRA_PROFILE_OWNER_NAME);
        String callingPackage = getCallingPackage();
        if (callingPackage == null || !callingPackage.equals(who.getPackageName())) {
            Log.e(TAG, "Unknown or incorrect caller");
            finish();
            return;
        }
        try {
            PackageInfo packageInfo = packageManager.getPackageInfo(callingPackage, 0);
            if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
                Log.e(TAG, "Cannot set a non-system app as a profile owner");
                finish();
                return;
            }
        } catch (NameNotFoundException nnfe) {
            Log.e(TAG, "Cannot find the package " + callingPackage);
            finish();
            return;
        }
    }
    ActivityInfo ai;
    try {
        ai = packageManager.getReceiverInfo(who, PackageManager.GET_META_DATA);
    } catch (PackageManager.NameNotFoundException e) {
        Log.w(TAG, "Unable to retrieve device policy " + who, e);
        finish();
        return;
    }
    // invalid device admin.
    if (!mDPM.isAdminActive(who)) {
        List<ResolveInfo> avail = packageManager.queryBroadcastReceivers(new Intent(DeviceAdminReceiver.ACTION_DEVICE_ADMIN_ENABLED), PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS);
        int count = avail == null ? 0 : avail.size();
        boolean found = false;
        for (int i = 0; i < count; i++) {
            ResolveInfo ri = avail.get(i);
            if (ai.packageName.equals(ri.activityInfo.packageName) && ai.name.equals(ri.activityInfo.name)) {
                try {
                    // We didn't retrieve the meta data for all possible matches, so
                    // need to use the activity info of this specific one that was retrieved.
                    ri.activityInfo = ai;
                    DeviceAdminInfo dpi = new DeviceAdminInfo(this, ri);
                    found = true;
                } catch (XmlPullParserException e) {
                    Log.w(TAG, "Bad " + ri.activityInfo, e);
                } catch (IOException e) {
                    Log.w(TAG, "Bad " + ri.activityInfo, e);
                }
                break;
            }
        }
        if (!found) {
            Log.w(TAG, "Request to add invalid device admin: " + who);
            finish();
            return;
        }
    }
    ResolveInfo ri = new ResolveInfo();
    ri.activityInfo = ai;
    try {
        mDeviceAdmin = new DeviceAdminInfo(this, ri);
    } catch (XmlPullParserException e) {
        Log.w(TAG, "Unable to retrieve device policy " + who, e);
        finish();
        return;
    } catch (IOException e) {
        Log.w(TAG, "Unable to retrieve device policy " + who, e);
        finish();
        return;
    }
    // "OK" immediately.
    if (DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN.equals(getIntent().getAction())) {
        mRefreshing = false;
        if (mDPM.isAdminActive(who)) {
            if (mDPM.isRemovingAdmin(who, android.os.Process.myUserHandle().getIdentifier())) {
                Log.w(TAG, "Requested admin is already being removed: " + who);
                finish();
                return;
            }
            ArrayList<DeviceAdminInfo.PolicyInfo> newPolicies = mDeviceAdmin.getUsedPolicies();
            for (int i = 0; i < newPolicies.size(); i++) {
                DeviceAdminInfo.PolicyInfo pi = newPolicies.get(i);
                if (!mDPM.hasGrantedPolicy(who, pi.ident)) {
                    mRefreshing = true;
                    break;
                }
            }
            if (!mRefreshing) {
                // Nothing changed (or policies were removed) - return immediately
                setResult(Activity.RESULT_OK);
                finish();
                return;
            }
        }
    }
    // need to prompt for permission. Just add and finish.
    if (mAddingProfileOwner && !mDPM.hasUserSetupCompleted()) {
        addAndFinish();
        return;
    }
    mAddMsgText = getIntent().getCharSequenceExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION);
    setContentView(R.layout.device_admin_add);
    mAdminIcon = (ImageView) findViewById(R.id.admin_icon);
    mAdminName = (TextView) findViewById(R.id.admin_name);
    mAdminDescription = (TextView) findViewById(R.id.admin_description);
    mProfileOwnerWarning = (TextView) findViewById(R.id.profile_owner_warning);
    mAddMsg = (TextView) findViewById(R.id.add_msg);
    mAddMsgExpander = (ImageView) findViewById(R.id.add_msg_expander);
    final View.OnClickListener onClickListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            toggleMessageEllipsis(mAddMsg);
        }
    };
    mAddMsgExpander.setOnClickListener(onClickListener);
    mAddMsg.setOnClickListener(onClickListener);
    // Determine whether the message can be collapsed - getLineCount() gives the correct
    // number of lines only after a layout pass.
    mAddMsg.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override
        public void onGlobalLayout() {
            final int maxLines = getEllipsizedLines();
            // hide the icon if number of visible lines does not exceed maxLines
            boolean hideMsgExpander = mAddMsg.getLineCount() <= maxLines;
            mAddMsgExpander.setVisibility(hideMsgExpander ? View.GONE : View.VISIBLE);
            if (hideMsgExpander) {
                mAddMsg.setOnClickListener(null);
                ((View) mAddMsgExpander.getParent()).invalidate();
            }
            mAddMsg.getViewTreeObserver().removeOnGlobalLayoutListener(this);
        }
    });
    // toggleMessageEllipsis also handles initial layout:
    toggleMessageEllipsis(mAddMsg);
    mAdminWarning = (TextView) findViewById(R.id.admin_warning);
    mAdminPolicies = (ViewGroup) findViewById(R.id.admin_policies);
    mSupportMessage = (TextView) findViewById(R.id.admin_support_message);
    mCancelButton = (Button) findViewById(R.id.cancel_button);
    mCancelButton.setFilterTouchesWhenObscured(true);
    mCancelButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            EventLog.writeEvent(EventLogTags.EXP_DET_DEVICE_ADMIN_DECLINED_BY_USER, mDeviceAdmin.getActivityInfo().applicationInfo.uid);
            finish();
        }
    });
    mUninstallButton = (Button) findViewById(R.id.uninstall_button);
    mUninstallButton.setFilterTouchesWhenObscured(true);
    mUninstallButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            EventLog.writeEvent(EventLogTags.EXP_DET_DEVICE_ADMIN_UNINSTALLED_BY_USER, mDeviceAdmin.getActivityInfo().applicationInfo.uid);
            mDPM.uninstallPackageWithActiveAdmins(mDeviceAdmin.getPackageName());
            finish();
        }
    });
    mActionButton = (Button) findViewById(R.id.action_button);
    mActionButton.setFilterTouchesWhenObscured(true);
    mActionButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (mAdding) {
                addAndFinish();
            } else if (isManagedProfile(mDeviceAdmin) && mDeviceAdmin.getComponent().equals(mDPM.getProfileOwner())) {
                final int userId = UserHandle.myUserId();
                UserDialogs.createRemoveDialog(DeviceAdminAdd.this, userId, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        UserManager um = UserManager.get(DeviceAdminAdd.this);
                        um.removeUser(userId);
                        finish();
                    }
                }).show();
            } else if (mUninstalling) {
                mDPM.uninstallPackageWithActiveAdmins(mDeviceAdmin.getPackageName());
                finish();
            } else if (!mWaitingForRemoveMsg) {
                try {
                    // Don't allow the admin to put a dialog up in front
                    // of us while we interact with the user.
                    ActivityManagerNative.getDefault().stopAppSwitches();
                } catch (RemoteException e) {
                }
                mWaitingForRemoveMsg = true;
                mDPM.getRemoveWarning(mDeviceAdmin.getComponent(), new RemoteCallback(new RemoteCallback.OnResultListener() {

                    @Override
                    public void onResult(Bundle result) {
                        CharSequence msg = result != null ? result.getCharSequence(DeviceAdminReceiver.EXTRA_DISABLE_WARNING) : null;
                        continueRemoveAction(msg);
                    }
                }, mHandler));
                // Don't want to wait too long.
                getWindow().getDecorView().getHandler().postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        continueRemoveAction(null);
                    }
                }, 2 * 1000);
            }
        }
    });
}
Also used : DialogInterface(android.content.DialogInterface) ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) ComponentName(android.content.ComponentName) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) ViewTreeObserver(android.view.ViewTreeObserver) ActivityInfo(android.content.pm.ActivityInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) Bundle(android.os.Bundle) Handler(android.os.Handler) Intent(android.content.Intent) IOException(java.io.IOException) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) RemoteCallback(android.os.RemoteCallback) UserManager(android.os.UserManager) DeviceAdminInfo(android.app.admin.DeviceAdminInfo) RemoteException(android.os.RemoteException)

Example 53 with ActivityInfo

use of android.content.pm.ActivityInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DeviceAdminSettings method addActiveAdminsForProfile.

/**
     * Add a {@link DeviceAdminInfo} object to the internal collection of available admins for all
     * active admin components associated with a profile.
     *
     * @param profileId a profile identifier.
     */
private void addActiveAdminsForProfile(final List<ComponentName> activeAdmins, final int profileId) {
    if (activeAdmins != null) {
        final PackageManager packageManager = getActivity().getPackageManager();
        final IPackageManager iPackageManager = AppGlobals.getPackageManager();
        final int n = activeAdmins.size();
        for (int i = 0; i < n; ++i) {
            final ComponentName activeAdmin = activeAdmins.get(i);
            final ActivityInfo ai;
            try {
                ai = iPackageManager.getReceiverInfo(activeAdmin, PackageManager.GET_META_DATA | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS | PackageManager.MATCH_ENCRYPTION_AWARE_AND_UNAWARE, profileId);
            } catch (RemoteException e) {
                Log.w(TAG, "Unable to load component: " + activeAdmin);
                continue;
            }
            final DeviceAdminInfo deviceAdminInfo = createDeviceAdminInfo(ai);
            if (deviceAdminInfo == null) {
                continue;
            }
            // Don't do the applicationInfo.isInternal() check here; if an active
            // admin is already on SD card, just show it.
            final DeviceAdminListItem item = new DeviceAdminListItem();
            item.info = deviceAdminInfo;
            item.name = deviceAdminInfo.loadLabel(packageManager).toString();
            item.active = true;
            mAdmins.add(item);
        }
    }
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) IPackageManager(android.content.pm.IPackageManager) DeviceAdminInfo(android.app.admin.DeviceAdminInfo) ComponentName(android.content.ComponentName) RemoteException(android.os.RemoteException)

Example 54 with ActivityInfo

use of android.content.pm.ActivityInfo in project android_frameworks_base by ResurrectionRemix.

the class Activity method shouldUpRecreateTask.

/**
     * Returns true if the app should recreate the task when navigating 'up' from this activity
     * by using targetIntent.
     *
     * <p>If this method returns false the app can trivially call
     * {@link #navigateUpTo(Intent)} using the same parameters to correctly perform
     * up navigation. If this method returns false, the app should synthesize a new task stack
     * by using {@link TaskStackBuilder} or another similar mechanism to perform up navigation.</p>
     *
     * @param targetIntent An intent representing the target destination for up navigation
     * @return true if navigating up should recreate a new task stack, false if the same task
     *         should be used for the destination
     */
public boolean shouldUpRecreateTask(Intent targetIntent) {
    try {
        PackageManager pm = getPackageManager();
        ComponentName cn = targetIntent.getComponent();
        if (cn == null) {
            cn = targetIntent.resolveActivity(pm);
        }
        ActivityInfo info = pm.getActivityInfo(cn, 0);
        if (info.taskAffinity == null) {
            return false;
        }
        return ActivityManagerNative.getDefault().shouldUpRecreateTask(mToken, info.taskAffinity);
    } catch (RemoteException e) {
        return false;
    } catch (NameNotFoundException e) {
        return false;
    }
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ComponentName(android.content.ComponentName) RemoteException(android.os.RemoteException)

Example 55 with ActivityInfo

use of android.content.pm.ActivityInfo in project android_frameworks_base by ResurrectionRemix.

the class Activity method getParentActivityIntent.

/**
     * Obtain an {@link Intent} that will launch an explicit target activity specified by
     * this activity's logical parent. The logical parent is named in the application's manifest
     * by the {@link android.R.attr#parentActivityName parentActivityName} attribute.
     * Activity subclasses may override this method to modify the Intent returned by
     * super.getParentActivityIntent() or to implement a different mechanism of retrieving
     * the parent intent entirely.
     *
     * @return a new Intent targeting the defined parent of this activity or null if
     *         there is no valid parent.
     */
@Nullable
public Intent getParentActivityIntent() {
    final String parentName = mActivityInfo.parentActivityName;
    if (TextUtils.isEmpty(parentName)) {
        return null;
    }
    // If the parent itself has no parent, generate a main activity intent.
    final ComponentName target = new ComponentName(this, parentName);
    try {
        final ActivityInfo parentInfo = getPackageManager().getActivityInfo(target, 0);
        final String parentActivity = parentInfo.parentActivityName;
        final Intent parentIntent = parentActivity == null ? Intent.makeMainActivity(target) : new Intent().setComponent(target);
        return parentIntent;
    } catch (NameNotFoundException e) {
        Log.e(TAG, "getParentActivityIntent: bad parentActivityName '" + parentName + "' in manifest");
        return null;
    }
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ComponentName(android.content.ComponentName) Intent(android.content.Intent) Nullable(android.annotation.Nullable)

Aggregations

ActivityInfo (android.content.pm.ActivityInfo)886 ResolveInfo (android.content.pm.ResolveInfo)360 Intent (android.content.Intent)339 ComponentName (android.content.ComponentName)324 PackageManager (android.content.pm.PackageManager)215 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)141 ArrayList (java.util.ArrayList)139 ApplicationInfo (android.content.pm.ApplicationInfo)115 Test (org.junit.Test)113 RemoteException (android.os.RemoteException)82 Bundle (android.os.Bundle)68 PendingIntent (android.app.PendingIntent)62 Drawable (android.graphics.drawable.Drawable)61 IOException (java.io.IOException)60 PackageInfo (android.content.pm.PackageInfo)59 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)54 XmlResourceParser (android.content.res.XmlResourceParser)43 Point (android.graphics.Point)35 SystemServicesProxy (com.android.systemui.recents.misc.SystemServicesProxy)34 Context (android.content.Context)33