Java Code Examples for android.os.UserHandle#myUserId()

The following examples show how to use android.os.UserHandle#myUserId() . 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: ApplicationPackageManager.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
private void onImplicitDirectBoot(int userId) {
    // Only report if someone is relying on implicit behavior while the user
    // is locked; code running when unlocked is going to see both aware and
    // unaware components.
    if (StrictMode.vmImplicitDirectBootEnabled()) {
        // We can cache the unlocked state for the userId we're running as,
        // since any relocking of that user will always result in our
        // process being killed to release any CE FDs we're holding onto.
        if (userId == UserHandle.myUserId()) {
            if (mUserUnlocked) {
                return;
            } else if (mContext.getSystemService(UserManager.class)
                    .isUserUnlockingOrUnlocked(userId)) {
                mUserUnlocked = true;
            } else {
                StrictMode.onImplicitDirectBoot();
            }
        } else if (!mContext.getSystemService(UserManager.class)
                .isUserUnlockingOrUnlocked(userId)) {
            StrictMode.onImplicitDirectBoot();
        }
    }
}
 
Example 2
Source File: TvRemoteProviderWatcher.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public TvRemoteProviderWatcher(Context context, ProviderMethods provider, Handler handler) {
    mContext = context;
    mProvider = provider;
    mHandler = handler;
    mUserId = UserHandle.myUserId();
    mPackageManager = context.getPackageManager();
    mUnbundledServicePackage = context.getString(
            com.android.internal.R.string.config_tvRemoteServicePackage);
}
 
Example 3
Source File: DiskStatsLoggingService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onStartJob(JobParameters params) {
    // We need to check the preconditions again because they may not be enforced for
    // subsequent runs.
    if (!isCharging(this) || !isDumpsysTaskEnabled(getContentResolver())) {
        jobFinished(params, true);
        return false;
    }


    VolumeInfo volume = getPackageManager().getPrimaryStorageCurrentVolume();
    // volume is null if the primary storage is not yet mounted.
    if (volume == null) {
        return false;
    }
    AppCollector collector = new AppCollector(this, volume);

    final int userId = UserHandle.myUserId();
    UserEnvironment environment = new UserEnvironment(userId);
    LogRunnable task = new LogRunnable();
    task.setDownloadsDirectory(
            environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS));
    task.setSystemSize(FileCollector.getSystemSize(this));
    task.setLogOutputFile(new File(DUMPSYS_CACHE_PATH));
    task.setAppCollector(collector);
    task.setJobService(this, params);
    task.setContext(this);
    AsyncTask.execute(task);
    return true;
}
 
Example 4
Source File: InputContentInfo.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * @return Content URI with which the content can be obtained.
 */
@NonNull
public Uri getContentUri() {
    // Fix up the content URI when and only when the caller's user ID does not match the owner's
    // user ID.
    if (mContentUriOwnerUserId != UserHandle.myUserId()) {
        return ContentProvider.maybeAddUserId(mContentUri, mContentUriOwnerUserId);
    }
    return mContentUri;
}
 
Example 5
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
public Object createService(ContextImpl ctx) {
    IBinder iBinder = ServiceManager.getService(Context.PRINT_SERVICE);
    IPrintManager service = IPrintManager.Stub.asInterface(iBinder);
    return new PrintManager(ctx.getOuterContext(), service, UserHandle.myUserId(),
            UserHandle.getAppId(Process.myUid()));
}
 
Example 6
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
public Object createService(ContextImpl ctx) {
    IBinder iBinder = ServiceManager.getService(TV_INPUT_SERVICE);
    ITvInputManager service = ITvInputManager.Stub.asInterface(iBinder);
    return new TvInputManager(service, UserHandle.myUserId());
}
 
Example 7
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
public Object createService(ContextImpl ctx) {
    IBinder iBinder = ServiceManager.getService(Context.PRINT_SERVICE);
    IPrintManager service = IPrintManager.Stub.asInterface(iBinder);
    return new PrintManager(ctx.getOuterContext(), service, UserHandle.myUserId(),
            UserHandle.getAppId(Process.myUid()));
}
 
Example 8
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
public Object createService(ContextImpl ctx) {
    IBinder iBinder = ServiceManager.getService(TV_INPUT_SERVICE);
    ITvInputManager service = ITvInputManager.Stub.asInterface(iBinder);
    return new TvInputManager(service, UserHandle.myUserId());
}
 
Example 9
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
public Object createService(ContextImpl ctx) {
    IBinder iBinder = ServiceManager.getService(Context.PRINT_SERVICE);
    IPrintManager service = IPrintManager.Stub.asInterface(iBinder);
    return new PrintManager(ctx.getOuterContext(), service, UserHandle.myUserId(),
            UserHandle.getAppId(Process.myUid()));
}
 
Example 10
Source File: PackageStats.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public PackageStats(String pkgName) {
    packageName = pkgName;
    userHandle = UserHandle.myUserId();
}
 
Example 11
Source File: LauncherApps.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Show an error log on logcat, when the calling user is a managed profile, and the target
 * user is different from the calling user, in order to help developers to detect it.
 */
private void logErrorForInvalidProfileAccess(@NonNull UserHandle target) {
    if (UserHandle.myUserId() != target.getIdentifier() && mUserManager.isManagedProfile()) {
        Log.w(TAG, "Accessing other profiles/users from managed profile is no longer allowed.");
    }
}