Search in sources :

Example 31 with ArraySet

use of android.util.ArraySet in project platform_frameworks_base by android.

the class PackageInstallerService method onSecureContainersAvailable.

public void onSecureContainersAvailable() {
    synchronized (mSessions) {
        final ArraySet<String> unclaimed = new ArraySet<>();
        for (String cid : PackageHelper.getSecureContainerList()) {
            if (isStageName(cid)) {
                unclaimed.add(cid);
            }
        }
        // Ignore stages claimed by active sessions
        for (int i = 0; i < mSessions.size(); i++) {
            final PackageInstallerSession session = mSessions.valueAt(i);
            final String cid = session.stageCid;
            if (unclaimed.remove(cid)) {
                // Claimed by active session, mount it
                PackageHelper.mountSdDir(cid, PackageManagerService.getEncryptKey(), Process.SYSTEM_UID);
            }
        }
        // Clean up orphaned staging containers
        for (String cid : unclaimed) {
            Slog.w(TAG, "Deleting orphan container " + cid);
            PackageHelper.destroySdDir(cid);
        }
    }
}
Also used : ArraySet(android.util.ArraySet) IPackageInstallerSession(android.content.pm.IPackageInstallerSession)

Example 32 with ArraySet

use of android.util.ArraySet in project platform_frameworks_base by android.

the class ManagedServices method updateSettingsAccordingToInstalledServices.

private void updateSettingsAccordingToInstalledServices(String setting, int userId) {
    boolean restoredChanged = false;
    boolean currentChanged = false;
    Set<ComponentName> restored = loadComponentNamesFromSetting(restoredSettingName(setting), userId);
    Set<ComponentName> current = loadComponentNamesFromSetting(setting, userId);
    // Load all services for all packages.
    Set<ComponentName> installed = queryPackageForServices(null, userId);
    ArraySet<ComponentName> retained = new ArraySet<>();
    for (ComponentName component : installed) {
        if (null != restored) {
            boolean wasRestored = restored.remove(component);
            if (wasRestored) {
                // Freshly installed package has service that was mentioned in restored setting.
                if (DEBUG)
                    Slog.v(TAG, "Restoring " + component + " for user " + userId);
                restoredChanged = true;
                currentChanged = true;
                retained.add(component);
                continue;
            }
        }
        if (null != current) {
            if (current.contains(component))
                retained.add(component);
        }
    }
    currentChanged |= ((current == null ? 0 : current.size()) != retained.size());
    if (currentChanged) {
        if (DEBUG)
            Slog.v(TAG, "List of  " + getCaption() + " services was updated " + current);
        storeComponentsToSetting(retained, setting, userId);
    }
    if (restoredChanged) {
        if (DEBUG)
            Slog.v(TAG, "List of  " + getCaption() + " restored services was updated " + restored);
        storeComponentsToSetting(restored, restoredSettingName(setting), userId);
    }
}
Also used : ArraySet(android.util.ArraySet) ComponentName(android.content.ComponentName)

Example 33 with ArraySet

use of android.util.ArraySet in project platform_frameworks_base by android.

the class ManagedServices method rebindServices.

/**
     * Called whenever packages change, the user switches, or the secure setting
     * is altered. (For example in response to USER_SWITCHED in our broadcast receiver)
     */
private void rebindServices(boolean forceRebind) {
    if (DEBUG)
        Slog.d(TAG, "rebindServices");
    final int[] userIds = mUserProfiles.getCurrentProfileIds();
    final int nUserIds = userIds.length;
    final SparseArray<ArraySet<ComponentName>> componentsByUser = new SparseArray<>();
    for (int i = 0; i < nUserIds; ++i) {
        componentsByUser.put(userIds[i], loadComponentNamesFromSetting(mConfig.secureSettingName, userIds[i]));
        if (mConfig.secondarySettingName != null) {
            componentsByUser.get(userIds[i]).addAll(loadComponentNamesFromSetting(mConfig.secondarySettingName, userIds[i]));
        }
    }
    final ArrayList<ManagedServiceInfo> removableBoundServices = new ArrayList<>();
    final SparseArray<Set<ComponentName>> toAdd = new SparseArray<>();
    synchronized (mMutex) {
        // Rebind to non-system services if user switched
        for (ManagedServiceInfo service : mServices) {
            if (!service.isSystem && !service.isGuest(this)) {
                removableBoundServices.add(service);
            }
        }
        mEnabledServicesForCurrentProfiles.clear();
        mEnabledServicesPackageNames.clear();
        for (int i = 0; i < nUserIds; ++i) {
            // decode the list of components
            final ArraySet<ComponentName> userComponents = componentsByUser.get(userIds[i]);
            if (null == userComponents) {
                toAdd.put(userIds[i], new ArraySet<ComponentName>());
                continue;
            }
            final Set<ComponentName> add = new HashSet<>(userComponents);
            add.removeAll(mSnoozingForCurrentProfiles);
            toAdd.put(userIds[i], add);
            mEnabledServicesForCurrentProfiles.addAll(userComponents);
            for (int j = 0; j < userComponents.size(); j++) {
                final ComponentName component = userComponents.valueAt(j);
                mEnabledServicesPackageNames.add(component.getPackageName());
            }
        }
    }
    for (ManagedServiceInfo info : removableBoundServices) {
        final ComponentName component = info.component;
        final int oldUser = info.userid;
        final Set<ComponentName> allowedComponents = toAdd.get(info.userid);
        if (allowedComponents != null) {
            if (allowedComponents.contains(component) && !forceRebind) {
                // Already bound, don't need to bind again.
                allowedComponents.remove(component);
            } else {
                // No longer allowed to be bound, or must rebind.
                Slog.v(TAG, "disabling " + getCaption() + " for user " + oldUser + ": " + component);
                unregisterService(component, oldUser);
            }
        }
    }
    for (int i = 0; i < nUserIds; ++i) {
        final Set<ComponentName> add = toAdd.get(userIds[i]);
        for (ComponentName component : add) {
            Slog.v(TAG, "enabling " + getCaption() + " for " + userIds[i] + ": " + component);
            registerService(component, userIds[i]);
        }
    }
    mLastSeenProfileIds = userIds;
}
Also used : ArraySet(android.util.ArraySet) HashSet(java.util.HashSet) ArraySet(android.util.ArraySet) Set(java.util.Set) ArrayList(java.util.ArrayList) SparseArray(android.util.SparseArray) ComponentName(android.content.ComponentName) HashSet(java.util.HashSet)

Example 34 with ArraySet

use of android.util.ArraySet in project platform_frameworks_base by android.

the class GlobalActions method createDialog.

/**
     * Create the global actions dialog.
     * @return A new dialog.
     */
private GlobalActionsDialog createDialog() {
    // Simple toggle style if there's no vibrator, otherwise use a tri-state
    if (!mHasVibrator) {
        mSilentModeAction = new SilentModeToggleAction();
    } else {
        mSilentModeAction = new SilentModeTriStateAction(mContext, mAudioManager, mHandler);
    }
    mAirplaneModeOn = new ToggleAction(R.drawable.ic_lock_airplane_mode, R.drawable.ic_lock_airplane_mode_off, R.string.global_actions_toggle_airplane_mode, R.string.global_actions_airplane_mode_on_status, R.string.global_actions_airplane_mode_off_status) {

        void onToggle(boolean on) {
            if (mHasTelephony && Boolean.parseBoolean(SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
                mIsWaitingForEcmExit = true;
                // Launch ECM exit dialog
                Intent ecmDialogIntent = new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null);
                ecmDialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                mContext.startActivity(ecmDialogIntent);
            } else {
                changeAirplaneModeSystemSetting(on);
            }
        }

        @Override
        protected void changeStateFromPress(boolean buttonOn) {
            if (!mHasTelephony)
                return;
            // In ECM mode airplane state cannot be changed
            if (!(Boolean.parseBoolean(SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE)))) {
                mState = buttonOn ? State.TurningOn : State.TurningOff;
                mAirplaneState = mState;
            }
        }

        public boolean showDuringKeyguard() {
            return true;
        }

        public boolean showBeforeProvisioning() {
            return false;
        }
    };
    onAirplaneModeChanged();
    mItems = new ArrayList<Action>();
    String[] defaultActions = mContext.getResources().getStringArray(com.android.internal.R.array.config_globalActionsList);
    ArraySet<String> addedKeys = new ArraySet<String>();
    for (int i = 0; i < defaultActions.length; i++) {
        String actionKey = defaultActions[i];
        if (addedKeys.contains(actionKey)) {
            // If we already have added this, don't add it again.
            continue;
        }
        if (GLOBAL_ACTION_KEY_POWER.equals(actionKey)) {
            mItems.add(new PowerAction());
        } else if (GLOBAL_ACTION_KEY_AIRPLANE.equals(actionKey)) {
            mItems.add(mAirplaneModeOn);
        } else if (GLOBAL_ACTION_KEY_BUGREPORT.equals(actionKey)) {
            if (Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.BUGREPORT_IN_POWER_MENU, 0) != 0 && isCurrentUserOwner()) {
                mItems.add(new BugReportAction());
            }
        } else if (GLOBAL_ACTION_KEY_SILENT.equals(actionKey)) {
            if (mShowSilentToggle) {
                mItems.add(mSilentModeAction);
            }
        } else if (GLOBAL_ACTION_KEY_USERS.equals(actionKey)) {
            if (SystemProperties.getBoolean("fw.power_user_switcher", false)) {
                addUsersToMenu(mItems);
            }
        } else if (GLOBAL_ACTION_KEY_SETTINGS.equals(actionKey)) {
            mItems.add(getSettingsAction());
        } else if (GLOBAL_ACTION_KEY_LOCKDOWN.equals(actionKey)) {
            mItems.add(getLockdownAction());
        } else if (GLOBAL_ACTION_KEY_VOICEASSIST.equals(actionKey)) {
            mItems.add(getVoiceAssistAction());
        } else if (GLOBAL_ACTION_KEY_ASSIST.equals(actionKey)) {
            mItems.add(getAssistAction());
        } else if (GLOBAL_ACTION_KEY_RESTART.equals(actionKey)) {
            mItems.add(new RestartAction());
        } else {
            Log.e(TAG, "Invalid global action key " + actionKey);
        }
        // Add here so we don't add more than one.
        addedKeys.add(actionKey);
    }
    if (mEmergencyAffordanceManager.needsEmergencyAffordance()) {
        mItems.add(getEmergencyAction());
    }
    mAdapter = new MyAdapter();
    AlertParams params = new AlertParams(mContext);
    params.mAdapter = mAdapter;
    params.mOnClickListener = this;
    params.mForceInverseBackground = true;
    GlobalActionsDialog dialog = new GlobalActionsDialog(mContext, params);
    // Handled by the custom class.
    dialog.setCanceledOnTouchOutside(false);
    dialog.getListView().setItemsCanFocus(true);
    dialog.getListView().setLongClickable(true);
    dialog.getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            final Action action = mAdapter.getItem(position);
            if (action instanceof LongPressAction) {
                return ((LongPressAction) action).onLongPress();
            }
            return false;
        }
    });
    dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
    dialog.setOnDismissListener(this);
    return dialog;
}
Also used : AlertParams(com.android.internal.app.AlertController.AlertParams) ArraySet(android.util.ArraySet) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AdapterView(android.widget.AdapterView)

Example 35 with ArraySet

use of android.util.ArraySet in project platform_frameworks_base by android.

the class TrustManagerService method maybeEnableFactoryTrustAgents.

private void maybeEnableFactoryTrustAgents(LockPatternUtils utils, int userId) {
    if (0 != Settings.Secure.getIntForUser(mContext.getContentResolver(), Settings.Secure.TRUST_AGENTS_INITIALIZED, 0, userId)) {
        return;
    }
    PackageManager pm = mContext.getPackageManager();
    List<ResolveInfo> resolveInfos = resolveAllowedTrustAgents(pm, userId);
    ArraySet<ComponentName> discoveredAgents = new ArraySet<>();
    for (ResolveInfo resolveInfo : resolveInfos) {
        ComponentName componentName = getComponentName(resolveInfo);
        int applicationInfoFlags = resolveInfo.serviceInfo.applicationInfo.flags;
        if ((applicationInfoFlags & ApplicationInfo.FLAG_SYSTEM) == 0) {
            Log.i(TAG, "Leaving agent " + componentName + " disabled because package " + "is not a system package.");
            continue;
        }
        discoveredAgents.add(componentName);
    }
    List<ComponentName> previouslyEnabledAgents = utils.getEnabledTrustAgents(userId);
    if (previouslyEnabledAgents != null) {
        discoveredAgents.addAll(previouslyEnabledAgents);
    }
    utils.setEnabledTrustAgents(discoveredAgents, userId);
    Settings.Secure.putIntForUser(mContext.getContentResolver(), Settings.Secure.TRUST_AGENTS_INITIALIZED, 1, userId);
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ArraySet(android.util.ArraySet) PackageManager(android.content.pm.PackageManager) ComponentName(android.content.ComponentName)

Aggregations

ArraySet (android.util.ArraySet)431 PublicKey (java.security.PublicKey)94 ComponentName (android.content.ComponentName)73 ArrayMap (android.util.ArrayMap)73 ArrayList (java.util.ArrayList)66 Pair (android.util.Pair)47 File (java.io.File)33 SSLContext (javax.net.ssl.SSLContext)32 Intent (android.content.Intent)30 RemoteException (android.os.RemoteException)29 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)28 ResolveInfo (android.content.pm.ResolveInfo)25 Point (android.graphics.Point)24 IOException (java.io.IOException)23 UserInfo (android.content.pm.UserInfo)21 X509Certificate (java.security.cert.X509Certificate)20 ContentResolver (android.content.ContentResolver)16 PackageManager (android.content.pm.PackageManager)15 NetworkPolicyManager.uidRulesToString (android.net.NetworkPolicyManager.uidRulesToString)15 SparseArray (android.util.SparseArray)15