android.content.pm.PackageManagerInternal Java Examples

The following examples show how to use android.content.pm.PackageManagerInternal. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NotificationRecord.java    From android_9.0.0_r45 with Apache License 2.0 7 votes vote down vote up
public NotificationRecord(Context context, StatusBarNotification sbn,
        NotificationChannel channel) {
    this.sbn = sbn;
    mTargetSdkVersion = LocalServices.getService(PackageManagerInternal.class)
            .getPackageTargetSdkVersion(sbn.getPackageName());
    mAm = ActivityManager.getService();
    mOriginalFlags = sbn.getNotification().flags;
    mRankingTimeMs = calculateRankingTimeMs(0L);
    mCreationTimeMs = sbn.getPostTime();
    mUpdateTimeMs = mCreationTimeMs;
    mInterruptionTimeMs = mCreationTimeMs;
    mContext = context;
    stats = new NotificationUsageStats.SingleNotificationStats();
    mChannel = channel;
    mPreChannelsNotification = isPreChannelsNotification();
    mSound = calculateSound();
    mVibration = calculateVibration();
    mAttributes = calculateAttributes();
    mImportance = calculateImportance();
    mLight = calculateLights();
    mAdjustments = new ArrayList<>();
    mStats = new NotificationStats();
    calculateUserSentiment();
    calculateGrantableUris();
}
 
Example #2
Source File: ActivityStartInterceptor.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private boolean interceptSuspendedPackageIfNeeded() {
    // Do not intercept if the package is not suspended
    if (mAInfo == null || mAInfo.applicationInfo == null ||
            (mAInfo.applicationInfo.flags & FLAG_SUSPENDED) == 0) {
        return false;
    }
    final PackageManagerInternal pmi = mService.getPackageManagerInternalLocked();
    if (pmi == null) {
        return false;
    }
    final String suspendedPackage = mAInfo.applicationInfo.packageName;
    final String suspendingPackage = pmi.getSuspendingPackage(suspendedPackage, mUserId);
    if (PLATFORM_PACKAGE_NAME.equals(suspendingPackage)) {
        return interceptSuspendedByAdminPackage();
    }
    final String dialogMessage = pmi.getSuspendedDialogMessage(suspendedPackage, mUserId);
    mIntent = SuspendedAppActivity.createSuspendedAppInterceptIntent(suspendedPackage,
            suspendingPackage, dialogMessage, mUserId);
    mCallingPid = mRealCallingPid;
    mCallingUid = mRealCallingUid;
    mResolvedType = null;
    mRInfo = mSupervisor.resolveIntent(mIntent, mResolvedType, mUserId, 0, mRealCallingUid);
    mAInfo = mSupervisor.resolveActivity(mIntent, mRInfo, mStartFlags, null /*profilerInfo*/);
    return true;
}
 
Example #3
Source File: LocationManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public LocationManagerService(Context context) {
    super();
    mContext = context;
    mAppOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);

    // Let the package manager query which are the default location
    // providers as they get certain permissions granted by default.
    PackageManagerInternal packageManagerInternal = LocalServices.getService(
            PackageManagerInternal.class);
    packageManagerInternal.setLocationPackagesProvider(
            new PackageManagerInternal.PackagesProvider() {
                @Override
                public String[] getPackages(int userId) {
                    return mContext.getResources().getStringArray(
                            com.android.internal.R.array.config_locationProviderPackageNames);
                }
            });

    if (D) Log.d(TAG, "Constructed");

    // most startup is deferred until systemRunning()
}
 
Example #4
Source File: ShortcutPackageInfo.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public int canRestoreTo(ShortcutService s, PackageInfo currentPackage, boolean anyVersionOkay) {
    PackageManagerInternal pmi = LocalServices.getService(PackageManagerInternal.class);
    if (!BackupUtils.signaturesMatch(mSigHashes, currentPackage, pmi)) {
        Slog.w(TAG, "Can't restore: Package signature mismatch");
        return ShortcutInfo.DISABLED_REASON_SIGNATURE_MISMATCH;
    }
    if (!ShortcutService.shouldBackupApp(currentPackage) || !mBackupSourceBackupAllowed) {
        // "allowBackup" was true when backed up, but now false.
        Slog.w(TAG, "Can't restore: package didn't or doesn't allow backup");
        return ShortcutInfo.DISABLED_REASON_BACKUP_NOT_SUPPORTED;
    }
    if (!anyVersionOkay && (currentPackage.getLongVersionCode() < mBackupSourceVersionCode)) {
        Slog.w(TAG, String.format(
                "Can't restore: package current version %d < backed up version %d",
                currentPackage.getLongVersionCode(), mBackupSourceVersionCode));
        return ShortcutInfo.DISABLED_REASON_VERSION_LOWER;
    }
    return ShortcutInfo.DISABLED_REASON_NOT_DISABLED;
}
 
Example #5
Source File: TelecomLoaderService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void registerCarrierConfigChangedReceiver() {
    final PackageManagerInternal packageManagerInternal = LocalServices.getService(
            PackageManagerInternal.class);
    BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
                for (int userId : UserManagerService.getInstance().getUserIds()) {
                    updateSimCallManagerPermissions(packageManagerInternal, userId);
                }
            }
        }
    };

    mContext.registerReceiverAsUser(receiver, UserHandle.ALL,
        new IntentFilter(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED), null, null);
}
 
Example #6
Source File: LauncherAppsService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isActivityEnabled(
        String callingPackage, ComponentName component, UserHandle user)
        throws RemoteException {
    if (!canAccessProfile(user.getIdentifier(), "Cannot check component")) {
        return false;
    }

    final int callingUid = injectBinderCallingUid();
    long ident = Binder.clearCallingIdentity();
    try {
        final PackageManagerInternal pmInt =
                LocalServices.getService(PackageManagerInternal.class);
        ActivityInfo info = pmInt.getActivityInfo(component,
                PackageManager.MATCH_DIRECT_BOOT_AWARE
                        | PackageManager.MATCH_DIRECT_BOOT_UNAWARE,
                callingUid, user.getIdentifier());
        return info != null;
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
 
Example #7
Source File: LauncherAppsService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public ApplicationInfo getApplicationInfo(
        String callingPackage, String packageName, int flags, UserHandle user)
        throws RemoteException {
    if (!canAccessProfile(user.getIdentifier(), "Cannot check package")) {
        return null;
    }

    final int callingUid = injectBinderCallingUid();
    long ident = Binder.clearCallingIdentity();
    try {
        final PackageManagerInternal pmInt =
                LocalServices.getService(PackageManagerInternal.class);
        ApplicationInfo info = pmInt.getApplicationInfo(packageName, flags,
                callingUid, user.getIdentifier());
        return info;
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
 
Example #8
Source File: LauncherAppsService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isPackageEnabled(String callingPackage, String packageName, UserHandle user)
        throws RemoteException {
    if (!canAccessProfile(user.getIdentifier(), "Cannot check package")) {
        return false;
    }

    final int callingUid = injectBinderCallingUid();
    long ident = Binder.clearCallingIdentity();
    try {
        final PackageManagerInternal pmInt =
                LocalServices.getService(PackageManagerInternal.class);
        PackageInfo info = pmInt.getPackageInfo(packageName,
                PackageManager.MATCH_DIRECT_BOOT_AWARE
                        | PackageManager.MATCH_DIRECT_BOOT_UNAWARE,
                callingUid, user.getIdentifier());
        return info != null && info.applicationInfo.enabled;
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
 
Example #9
Source File: Searchables.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private ArrayList<ResolveInfo> createFilterdResolveInfoList(List<ResolveInfo> list) {
    if (list == null) {
        return null;
    }
    final ArrayList<ResolveInfo> resultList = new ArrayList<>(list.size());
    final PackageManagerInternal pm = LocalServices.getService(PackageManagerInternal.class);
    final int callingUid = Binder.getCallingUid();
    final int callingUserId = UserHandle.getCallingUserId();
    for (ResolveInfo info : list) {
        if (pm.canAccessComponent(
                callingUid, info.activityInfo.getComponentName(), callingUserId)) {
            resultList.add(info);
        }
    }
    return resultList;
}
 
Example #10
Source File: LauncherAppsService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private ParceledListSlice<ResolveInfo> queryActivitiesForUser(String callingPackage,
        Intent intent, UserHandle user) {
    if (!canAccessProfile(user.getIdentifier(), "Cannot retrieve activities")) {
        return null;
    }

    final int callingUid = injectBinderCallingUid();
    long ident = injectClearCallingIdentity();
    try {
        final PackageManagerInternal pmInt =
                LocalServices.getService(PackageManagerInternal.class);
        List<ResolveInfo> apps = pmInt.queryIntentActivities(intent,
                PackageManager.MATCH_DIRECT_BOOT_AWARE
                        | PackageManager.MATCH_DIRECT_BOOT_UNAWARE,
                callingUid, user.getIdentifier());
        return new ParceledListSlice<>(apps);
    } finally {
        injectRestoreCallingIdentity(ident);
    }
}
 
Example #11
Source File: LauncherAppsService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public ActivityInfo resolveActivity(
        String callingPackage, ComponentName component, UserHandle user)
        throws RemoteException {
    if (!canAccessProfile(user.getIdentifier(), "Cannot resolve activity")) {
        return null;
    }

    final int callingUid = injectBinderCallingUid();
    long ident = Binder.clearCallingIdentity();
    try {
        final PackageManagerInternal pmInt =
                LocalServices.getService(PackageManagerInternal.class);
        return pmInt.getActivityInfo(component,
                PackageManager.MATCH_DIRECT_BOOT_AWARE
                        | PackageManager.MATCH_DIRECT_BOOT_UNAWARE,
                callingUid, user.getIdentifier());
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
 
Example #12
Source File: SliceManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
SliceManagerService(Context context, Looper looper) {
    mContext = context;
    mPackageManagerInternal = Preconditions.checkNotNull(
            LocalServices.getService(PackageManagerInternal.class));
    mAppOps = context.getSystemService(AppOpsManager.class);
    mAssistUtils = new AssistUtils(context);
    mHandler = new Handler(looper);

    mAppUsageStats = LocalServices.getService(UsageStatsManagerInternal.class);

    mPermissions = new SlicePermissionManager(mContext, looper);

    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_PACKAGE_DATA_CLEARED);
    filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    filter.addDataScheme("package");
    mContext.registerReceiverAsUser(mReceiver, UserHandle.ALL, filter, null, mHandler);
}
 
Example #13
Source File: DefaultPermissionGrantPolicy.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private boolean isSysComponentOrPersistentPlatformSignedPrivApp(PackageParser.Package pkg) {
    if (UserHandle.getAppId(pkg.applicationInfo.uid) < FIRST_APPLICATION_UID) {
        return true;
    }
    if (!pkg.isPrivileged()) {
        return false;
    }
    final PackageParser.Package disabledPkg =
            mServiceInternal.getDisabledPackage(pkg.packageName);
    if (disabledPkg != null) {
        if ((disabledPkg.applicationInfo.flags & ApplicationInfo.FLAG_PERSISTENT) == 0) {
            return false;
        }
    } else if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_PERSISTENT) == 0) {
        return false;
    }
    final String systemPackageName = mServiceInternal.getKnownPackageName(
            PackageManagerInternal.PACKAGE_SYSTEM, UserHandle.USER_SYSTEM);
    final PackageParser.Package systemPackage = getPackage(systemPackageName);
    return pkg.mSigningDetails.hasAncestorOrSelf(systemPackage.mSigningDetails)
            || systemPackage.mSigningDetails.checkCapability(pkg.mSigningDetails,
                    PackageParser.SigningDetails.CertCapabilities.PERMISSION);
}
 
Example #14
Source File: DefaultPermissionGrantPolicy.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public DefaultPermissionGrantPolicy(Context context, Looper looper,
        @Nullable DefaultPermissionGrantedCallback callback,
        @NonNull PermissionManagerService permissionManager) {
    mContext = context;
    mHandler = new Handler(looper) {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == MSG_READ_DEFAULT_PERMISSION_EXCEPTIONS) {
                synchronized (mLock) {
                    if (mGrantExceptions == null) {
                        mGrantExceptions = readDefaultPermissionExceptionsLocked();
                    }
                }
            }
        }
    };
    mPermissionGrantedCallback = callback;
    mPermissionManager = permissionManager;
    mServiceInternal = LocalServices.getService(PackageManagerInternal.class);
}
 
Example #15
Source File: ComponentResolver.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
ComponentResolver(UserManagerService userManager,
        PackageManagerInternal packageManagerInternal,
        Object lock) {
    sPackageManagerInternal = packageManagerInternal;
    sUserManager = userManager;
    mLock = lock;
}
 
Example #16
Source File: LauncherAppsService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public Bundle getSuspendedPackageLauncherExtras(String packageName,
        UserHandle user) {
    if (!canAccessProfile(user.getIdentifier(), "Cannot get launcher extras")) {
        return null;
    }
    final PackageManagerInternal pmi =
            LocalServices.getService(PackageManagerInternal.class);
    return pmi.getSuspendedPackageLauncherExtras(packageName, user.getIdentifier());
}
 
Example #17
Source File: TelecomLoaderService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void registerDefaultAppNotifier() {
    final PackageManagerInternal packageManagerInternal = LocalServices.getService(
            PackageManagerInternal.class);

    // Notify the package manager on default app changes
    final Uri defaultSmsAppUri = Settings.Secure.getUriFor(
            Settings.Secure.SMS_DEFAULT_APPLICATION);
    final Uri defaultDialerAppUri = Settings.Secure.getUriFor(
            Settings.Secure.DIALER_DEFAULT_APPLICATION);

    ContentObserver contentObserver = new ContentObserver(
            new Handler(Looper.getMainLooper())) {
        @Override
        public void onChange(boolean selfChange, Uri uri, int userId) {
            if (defaultSmsAppUri.equals(uri)) {
                ComponentName smsComponent = SmsApplication.getDefaultSmsApplication(
                        mContext, true);
                if (smsComponent != null) {
                    packageManagerInternal.grantDefaultPermissionsToDefaultSmsApp(
                            smsComponent.getPackageName(), userId);
                }
            } else if (defaultDialerAppUri.equals(uri)) {
                String packageName = DefaultDialerManager.getDefaultDialerApplication(
                        mContext);
                if (packageName != null) {
                    packageManagerInternal.grantDefaultPermissionsToDefaultDialerApp(
                            packageName, userId);
                }
                updateSimCallManagerPermissions(packageManagerInternal, userId);
            }
        }
    };

    mContext.getContentResolver().registerContentObserver(defaultSmsAppUri,
            false, contentObserver, UserHandle.USER_ALL);
    mContext.getContentResolver().registerContentObserver(defaultDialerAppUri,
            false, contentObserver, UserHandle.USER_ALL);
}
 
Example #18
Source File: ContentService.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
ContentService(Context context, boolean factoryTest) {
    mContext = context;
    mFactoryTest = factoryTest;

    // Let the package manager query for the sync adapters for a given authority
    // as we grant default permissions to sync adapters for specific authorities.
    PackageManagerInternal packageManagerInternal = LocalServices.getService(
            PackageManagerInternal.class);
    packageManagerInternal.setSyncAdapterPackagesprovider(
            new PackageManagerInternal.SyncAdapterPackagesProvider() {
                @Override
                public String[] getPackages(String authority, int userId) {
                    return getSyncAdapterPackagesForAuthorityAsUser(authority, userId);
                }
            });

    final IntentFilter packageFilter = new IntentFilter();
    packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    packageFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    packageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    packageFilter.addAction(Intent.ACTION_PACKAGE_DATA_CLEARED);
    packageFilter.addDataScheme("package");
    mContext.registerReceiverAsUser(mCacheReceiver, UserHandle.ALL,
            packageFilter, null, null);

    final IntentFilter localeFilter = new IntentFilter();
    localeFilter.addAction(Intent.ACTION_LOCALE_CHANGED);
    mContext.registerReceiverAsUser(mCacheReceiver, UserHandle.ALL,
            localeFilter, null, null);
}
 
Example #19
Source File: ContentService.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
ContentService(Context context, boolean factoryTest) {
    mContext = context;
    mFactoryTest = factoryTest;

    // Let the package manager query for the sync adapters for a given authority
    // as we grant default permissions to sync adapters for specific authorities.
    PackageManagerInternal packageManagerInternal = LocalServices.getService(
            PackageManagerInternal.class);
    packageManagerInternal.setSyncAdapterPackagesprovider(
            new PackageManagerInternal.SyncAdapterPackagesProvider() {
                @Override
                public String[] getPackages(String authority, int userId) {
                    return getSyncAdapterPackagesForAuthorityAsUser(authority, userId);
                }
            });

    final IntentFilter packageFilter = new IntentFilter();
    packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    packageFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    packageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    packageFilter.addAction(Intent.ACTION_PACKAGE_DATA_CLEARED);
    packageFilter.addDataScheme("package");
    mContext.registerReceiverAsUser(mCacheReceiver, UserHandle.ALL,
            packageFilter, null, null);

    final IntentFilter localeFilter = new IntentFilter();
    localeFilter.addAction(Intent.ACTION_LOCALE_CHANGED);
    mContext.registerReceiverAsUser(mCacheReceiver, UserHandle.ALL,
            localeFilter, null, null);
}
 
Example #20
Source File: PruneInstantAppsJobService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onStartJob(JobParameters params) {
    AsyncTask.execute(() -> {
        PackageManagerInternal packageManagerInternal = LocalServices.getService(
                PackageManagerInternal.class);
        packageManagerInternal.pruneInstantApps();
        jobFinished(params, false);
    });
    return true;
}
 
Example #21
Source File: ContentService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
ContentService(Context context, boolean factoryTest) {
    mContext = context;
    mFactoryTest = factoryTest;

    // Let the package manager query for the sync adapters for a given authority
    // as we grant default permissions to sync adapters for specific authorities.
    PackageManagerInternal packageManagerInternal = LocalServices.getService(
            PackageManagerInternal.class);
    packageManagerInternal.setSyncAdapterPackagesprovider(
            new PackageManagerInternal.SyncAdapterPackagesProvider() {
                @Override
                public String[] getPackages(String authority, int userId) {
                    return getSyncAdapterPackagesForAuthorityAsUser(authority, userId);
                }
            });

    final IntentFilter packageFilter = new IntentFilter();
    packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    packageFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    packageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    packageFilter.addAction(Intent.ACTION_PACKAGE_DATA_CLEARED);
    packageFilter.addDataScheme("package");
    mContext.registerReceiverAsUser(mCacheReceiver, UserHandle.ALL,
            packageFilter, null, null);

    final IntentFilter localeFilter = new IntentFilter();
    localeFilter.addAction(Intent.ACTION_LOCALE_CHANGED);
    mContext.registerReceiverAsUser(mCacheReceiver, UserHandle.ALL,
            localeFilter, null, null);
}
 
Example #22
Source File: TelecomLoaderService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void updateSimCallManagerPermissions(PackageManagerInternal packageManagerInternal,
        int userId) {
    TelecomManager telecomManager =
        (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
    PhoneAccountHandle phoneAccount = telecomManager.getSimCallManager(userId);
    if (phoneAccount != null) {
        Slog.i(TAG, "updating sim call manager permissions for userId:" + userId);
        String packageName = phoneAccount.getComponentName().getPackageName();
        packageManagerInternal.grantDefaultPermissionsToDefaultSimCallManager(
            packageName, userId);
    }
}
 
Example #23
Source File: Searchables.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private ArrayList<SearchableInfo> createFilterdSearchableInfoList(List<SearchableInfo> list) {
    if (list == null) {
        return null;
    }
    final ArrayList<SearchableInfo> resultList = new ArrayList<>(list.size());
    final PackageManagerInternal pm = LocalServices.getService(PackageManagerInternal.class);
    final int callingUid = Binder.getCallingUid();
    final int callingUserId = UserHandle.getCallingUserId();
    for (SearchableInfo info : list) {
        if (pm.canAccessComponent(callingUid, info.getSearchActivity(), callingUserId)) {
            resultList.add(info);
        }
    }
    return resultList;
}
 
Example #24
Source File: Searchables.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the name of the global search activity.
 */
public synchronized ComponentName getGlobalSearchActivity() {
    final PackageManagerInternal pm = LocalServices.getService(PackageManagerInternal.class);
    final int callingUid = Binder.getCallingUid();
    final int callingUserId = UserHandle.getCallingUserId();
    if (mCurrentGlobalSearchActivity != null
            && pm.canAccessComponent(callingUid, mCurrentGlobalSearchActivity, callingUserId)) {
        return mCurrentGlobalSearchActivity;
    }
    return null;
}
 
Example #25
Source File: Searchables.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the name of the web search activity.
 */
public synchronized ComponentName getWebSearchActivity() {
    final PackageManagerInternal pm = LocalServices.getService(PackageManagerInternal.class);
    final int callingUid = Binder.getCallingUid();
    final int callingUserId = UserHandle.getCallingUserId();
    if (mWebSearchActivity != null
            && pm.canAccessComponent(callingUid, mWebSearchActivity, callingUserId)) {
        return mWebSearchActivity;
    }
    return null;
}
 
Example #26
Source File: JobSchedulerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Initializes the system service.
 * <p>
 * Subclasses must define a single argument constructor that accepts the context
 * and passes it to super.
 * </p>
 *
 * @param context The system server context.
 */
public JobSchedulerService(Context context) {
    super(context);

    mLocalPM = LocalServices.getService(PackageManagerInternal.class);
    mActivityManagerInternal = Preconditions.checkNotNull(
            LocalServices.getService(ActivityManagerInternal.class));

    mHandler = new JobHandler(context.getMainLooper());
    mConstants = new Constants();
    mConstantsObserver = new ConstantsObserver(mHandler);
    mJobSchedulerStub = new JobSchedulerStub();

    // Set up the app standby bucketing tracker
    mStandbyTracker = new StandbyTracker();
    mUsageStats = LocalServices.getService(UsageStatsManagerInternal.class);
    mUsageStats.addAppIdleStateChangeListener(mStandbyTracker);

    // The job store needs to call back
    publishLocalService(JobSchedulerInternal.class, new LocalService());

    // Initialize the job store and set up any persisted jobs
    mJobs = JobStore.initAndGet(this);

    // Create the controllers.
    mControllers = new ArrayList<StateController>();
    mControllers.add(new ConnectivityController(this));
    mControllers.add(new TimeController(this));
    mControllers.add(new IdleController(this));
    mBatteryController = new BatteryController(this);
    mControllers.add(mBatteryController);
    mStorageController = new StorageController(this);
    mControllers.add(mStorageController);
    mControllers.add(new BackgroundJobsController(this));
    mControllers.add(new ContentObserverController(this));
    mDeviceIdleJobsController = new DeviceIdleJobsController(this);
    mControllers.add(mDeviceIdleJobsController);

    // If the job store determined that it can't yet reschedule persisted jobs,
    // we need to start watching the clock.
    if (!mJobs.jobTimesInflatedValid()) {
        Slog.w(TAG, "!!! RTC not yet good; tracking time updates for job scheduling");
        context.registerReceiver(mTimeSetReceiver, new IntentFilter(Intent.ACTION_TIME_CHANGED));
    }
}
 
Example #27
Source File: JobStatus.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private static int resolveTargetSdkVersion(JobInfo job) {
    return LocalServices.getService(PackageManagerInternal.class)
            .getPackageTargetSdkVersion(job.getService().getPackageName());
}
 
Example #28
Source File: LauncherAppsService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void startActivityAsUser(IApplicationThread caller, String callingPackage,
        ComponentName component, Rect sourceBounds,
        Bundle opts, UserHandle user) throws RemoteException {
    if (!canAccessProfile(user.getIdentifier(), "Cannot start activity")) {
        return;
    }

    Intent launchIntent = new Intent(Intent.ACTION_MAIN);
    launchIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    launchIntent.setSourceBounds(sourceBounds);
    launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
            | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    launchIntent.setPackage(component.getPackageName());

    boolean canLaunch = false;

    final int callingUid = injectBinderCallingUid();
    long ident = Binder.clearCallingIdentity();
    try {
        final PackageManagerInternal pmInt =
                LocalServices.getService(PackageManagerInternal.class);
        ActivityInfo info = pmInt.getActivityInfo(component,
                PackageManager.MATCH_DIRECT_BOOT_AWARE
                        | PackageManager.MATCH_DIRECT_BOOT_UNAWARE,
                callingUid, user.getIdentifier());
        if (!info.exported) {
            throw new SecurityException("Cannot launch non-exported components "
                    + component);
        }

        // Check that the component actually has Intent.CATEGORY_LAUCNCHER
        // as calling startActivityAsUser ignores the category and just
        // resolves based on the component if present.
        List<ResolveInfo> apps = pmInt.queryIntentActivities(launchIntent,
                PackageManager.MATCH_DIRECT_BOOT_AWARE
                        | PackageManager.MATCH_DIRECT_BOOT_UNAWARE,
                callingUid, user.getIdentifier());
        final int size = apps.size();
        for (int i = 0; i < size; ++i) {
            ActivityInfo activityInfo = apps.get(i).activityInfo;
            if (activityInfo.packageName.equals(component.getPackageName()) &&
                    activityInfo.name.equals(component.getClassName())) {
                // Found an activity with category launcher that matches
                // this component so ok to launch.
                launchIntent.setPackage(null);
                launchIntent.setComponent(component);
                canLaunch = true;
                break;
            }
        }
        if (!canLaunch) {
            throw new SecurityException("Attempt to launch activity without "
                    + " category Intent.CATEGORY_LAUNCHER " + component);
        }
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
    mActivityManagerInternal.startActivityAsUser(caller, callingPackage,
            launchIntent, opts, user.getIdentifier());
}
 
Example #29
Source File: CrossProfileAppsServiceImpl.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public PackageManagerInternal getPackageManagerInternal() {
    return LocalServices.getService(PackageManagerInternal.class);
}
 
Example #30
Source File: ShortcutService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
ShortcutService(Context context, Looper looper, boolean onlyForPackageManagerApis) {
    mContext = Preconditions.checkNotNull(context);
    LocalServices.addService(ShortcutServiceInternal.class, new LocalService());
    mHandler = new Handler(looper);
    mIPackageManager = AppGlobals.getPackageManager();
    mPackageManagerInternal = Preconditions.checkNotNull(
            LocalServices.getService(PackageManagerInternal.class));
    mUserManagerInternal = Preconditions.checkNotNull(
            LocalServices.getService(UserManagerInternal.class));
    mUsageStatsManagerInternal = Preconditions.checkNotNull(
            LocalServices.getService(UsageStatsManagerInternal.class));
    mActivityManagerInternal = Preconditions.checkNotNull(
            LocalServices.getService(ActivityManagerInternal.class));

    mShortcutRequestPinProcessor = new ShortcutRequestPinProcessor(this, mLock);
    mShortcutBitmapSaver = new ShortcutBitmapSaver(this);
    mShortcutDumpFiles = new ShortcutDumpFiles(this);

    if (onlyForPackageManagerApis) {
        return; // Don't do anything further.  For unit tests only.
    }

    // Register receivers.

    // We need to set a priority, so let's just not use PackageMonitor for now.
    // TODO Refactor PackageMonitor to support priorities.
    final IntentFilter packageFilter = new IntentFilter();
    packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    packageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    packageFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    packageFilter.addAction(Intent.ACTION_PACKAGE_DATA_CLEARED);
    packageFilter.addDataScheme("package");
    packageFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
    mContext.registerReceiverAsUser(mPackageMonitor, UserHandle.ALL,
            packageFilter, null, mHandler);

    final IntentFilter preferedActivityFilter = new IntentFilter();
    preferedActivityFilter.addAction(Intent.ACTION_PREFERRED_ACTIVITY_CHANGED);
    preferedActivityFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
    mContext.registerReceiverAsUser(mPackageMonitor, UserHandle.ALL,
            preferedActivityFilter, null, mHandler);

    final IntentFilter localeFilter = new IntentFilter();
    localeFilter.addAction(Intent.ACTION_LOCALE_CHANGED);
    localeFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
    mContext.registerReceiverAsUser(mReceiver, UserHandle.ALL,
            localeFilter, null, mHandler);

    injectRegisterUidObserver(mUidObserver, ActivityManager.UID_OBSERVER_PROCSTATE
            | ActivityManager.UID_OBSERVER_GONE);
}