Java Code Examples for android.os.Binder#restoreCallingIdentity()

The following examples show how to use android.os.Binder#restoreCallingIdentity() . 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: FingerprintService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override // Binder call
public boolean isHardwareDetected(long deviceId, String opPackageName) {
    if (!canUseFingerprint(opPackageName, false /* foregroundOnly */,
            Binder.getCallingUid(), Binder.getCallingPid(),
            UserHandle.getCallingUserId())) {
        return false;
    }

    final long token = Binder.clearCallingIdentity();
    try {
        IBiometricsFingerprint daemon = getFingerprintDaemon();
        return daemon != null && mHalDeviceId != 0;
    } finally {
        Binder.restoreCallingIdentity(token);
    }
}
 
Example 2
Source File: NonMediaDocumentsProvider.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@Override
public ParcelFileDescriptor openDocument(String docId, String mode, CancellationSignal signal)
        throws FileNotFoundException {

    if (!"r".equals(mode)) {
        throw new IllegalArgumentException("Media is read-only");
    }

    final Uri target = getUriForDocumentId(docId);

    // Delegate to real provider
    final long token = Binder.clearCallingIdentity();
    try {
        return getContext().getContentResolver().openFileDescriptor(target, mode);
    } finally {
        Binder.restoreCallingIdentity(token);
    }
}
 
Example 3
Source File: DownloadStorageProvider.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@Override
public Cursor queryChildDocuments(String docId, String[] projection, String sortOrder)
        throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));

    // Delegate to real provider
    final long token = Binder.clearCallingIdentity();
    Cursor cursor = null;
    try {
    	Query query = new Query();
    	DownloadManagerUtils.setOnlyIncludeVisibleInDownloadsUi(query);
    	//query.setOnlyIncludeVisibleInDownloadsUi(true);
        query.setFilterByStatus(DownloadManager.STATUS_SUCCESSFUL);
    	//query.setFilterByStatus(DownloadManager.STATUS_PENDING | DownloadManager.STATUS_PAUSED | DownloadManager.STATUS_RUNNING | DownloadManager.STATUS_FAILED);
        cursor = mDm.query(query);//.setOnlyIncludeVisibleInDownloadsUi(true)
                //.setFilterByStatus(DownloadManager.STATUS_SUCCESSFUL));
        //copyNotificationUri(result, cursor);
        while (cursor.moveToNext()) {
            includeDownloadFromCursor(result, cursor);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
        Binder.restoreCallingIdentity(token);
    }
    return result;
}
 
Example 4
Source File: TvRemoteProviderProxy.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
void sendPointerUp(final IBinder token, final int pointerId) {
    synchronized (mLock) {
        if (mActiveConnection == this && Binder.getCallingUid() == mUid) {
            if (DEBUG_KEY) {
                Slog.d(TAG, this + ": sendPointerUp," +
                        " token=" + token + ", pointerId=" + pointerId);
            }
            final long idToken = Binder.clearCallingIdentity();
            try {
                if (mProviderMethods != null) {
                    mProviderMethods.sendPointerUp(TvRemoteProviderProxy.this, token,
                            pointerId);
                }
            } finally {
                Binder.restoreCallingIdentity(idToken);
            }
        } else {
            if (DEBUG) {
                Slog.w(TAG,
                        "sendPointerUp, Invalid connection or incorrect uid: " + Binder
                                .getCallingUid());
            }
        }
    }
}
 
Example 5
Source File: DownloadStorageProvider.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@Override
public Cursor queryChildDocumentsForManage(
        String parentDocumentId, String[] projection, String sortOrder)
        throws FileNotFoundException {
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));

    // Delegate to real provider
    final long token = Binder.clearCallingIdentity();
    Cursor cursor = null;
    try {
        cursor = mDm.query(
                new DownloadManager.Query());//.setOnlyIncludeVisibleInDownloadsUi(true));
        //copyNotificationUri(result, cursor);
        while (cursor.moveToNext()) {
            includeDownloadFromCursor(result, cursor);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
        Binder.restoreCallingIdentity(token);
    }
    return result;
}
 
Example 6
Source File: StatsCompanionService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void pullMobileBytesTransfer(int tagId, List<StatsLogEventWrapper> pulledData) {
    long token = Binder.clearCallingIdentity();
    try {
        BatteryStatsInternal bs = LocalServices.getService(BatteryStatsInternal.class);
        String[] ifaces = bs.getMobileIfaces();
        if (ifaces.length == 0) {
            return;
        }
        NetworkStatsFactory nsf = new NetworkStatsFactory();
        // Combine all the metrics per Uid into one record.
        NetworkStats stats =
                nsf.readNetworkStatsDetail(NetworkStats.UID_ALL, ifaces, NetworkStats.TAG_NONE, null)
                        .groupedByUid();
        addNetworkStats(tagId, pulledData, stats, false);
    } catch (java.io.IOException e) {
        Slog.e(TAG, "Pulling netstats for mobile bytes has error", e);
    } finally {
        Binder.restoreCallingIdentity(token);
    }
}
 
Example 7
Source File: PowerManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override // Binder call
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
    if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;

    final long ident = Binder.clearCallingIdentity();

    boolean isDumpProto = false;
    for (String arg : args) {
        if (arg.equals("--proto")) {
            isDumpProto = true;
        }
    }
    try {
        if (isDumpProto) {
            dumpProto(fd);
        } else {
            dumpInternal(pw);
        }
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
 
Example 8
Source File: DownloadStorageProvider.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
@Override
public ParcelFileDescriptor openDocument(String docId, String mode, CancellationSignal signal)
        throws FileNotFoundException {
    // Delegate to real provider
    final long token = Binder.clearCallingIdentity();
    try {
        final long id = Long.parseLong(docId);
        final ContentResolver resolver = getContext().getContentResolver();
        return resolver.openFileDescriptor(mDm.getUriForDownloadedFile(id), mode);
    } finally {
        Binder.restoreCallingIdentity(token);
    }
}
 
Example 9
Source File: SettingsProvider.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
private void ensureSecureSettingAndroidIdSetLocked(SettingsState secureSettings) {
    Setting value = secureSettings.getSettingLocked(Settings.Secure.ANDROID_ID);

    if (!value.isNull()) {
        return;
    }

    final int userId = getUserIdFromKey(secureSettings.mKey);

    final UserInfo user;
    final long identity = Binder.clearCallingIdentity();
    try {
        user = mUserManager.getUserInfo(userId);
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
    if (user == null) {
        // Can happen due to races when deleting users - treat as benign.
        return;
    }

    String androidId = Long.toHexString(new SecureRandom().nextLong());
    secureSettings.insertSettingLocked(Settings.Secure.ANDROID_ID, androidId,
            null, true, SettingsState.SYSTEM_PACKAGE_NAME);

    Slog.d(LOG_TAG, "Generated and saved new ANDROID_ID [" + androidId
            + "] for user " + userId);

    // Write a drop box entry if it's a restricted profile
    if (user.isRestricted()) {
        DropBoxManager dbm = (DropBoxManager) getContext().getSystemService(
                Context.DROPBOX_SERVICE);
        if (dbm != null && dbm.isTagEnabled(DROPBOX_TAG_USERLOG)) {
            dbm.addText(DROPBOX_TAG_USERLOG, System.currentTimeMillis()
                    + "," + DROPBOX_TAG_USERLOG + "," + androidId + "\n");
        }
    }
}
 
Example 10
Source File: MediaSessionRecord.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void setActive(boolean active) {
    mIsActive = active;
    final long token = Binder.clearCallingIdentity();
    try {
        mService.updateSession(MediaSessionRecord.this);
    } finally {
        Binder.restoreCallingIdentity(token);
    }
    mHandler.post(MessageHandler.MSG_UPDATE_SESSION_STATE);
}
 
Example 11
Source File: Session.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void cancelDragAndDrop(IBinder dragToken) {
    final long ident = Binder.clearCallingIdentity();
    try {
        mDragDropController.cancelDragAndDrop(dragToken);
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
 
Example 12
Source File: LocationManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void removeTestProvider(String provider, String opPackageName) {
    if (!canCallerAccessMockLocation(opPackageName)) {
        return;
    }

    synchronized (mLock) {

        // These methods can't be called after removing the test provider, so first make sure
        // we don't leave anything dangling.
        clearTestProviderEnabled(provider, opPackageName);
        clearTestProviderLocation(provider, opPackageName);
        clearTestProviderStatus(provider, opPackageName);

        MockProvider mockProvider = mMockProviders.remove(provider);
        if (mockProvider == null) {
            throw new IllegalArgumentException("Provider \"" + provider + "\" unknown");
        }
        long identity = Binder.clearCallingIdentity();
        removeProviderLocked(mProvidersByName.get(provider));

        // reinstate real provider if available
        LocationProviderInterface realProvider = mRealProviders.get(provider);
        if (realProvider != null) {
            addProviderLocked(realProvider);
        }
        mLastLocation.put(provider, null);
        mLastLocationCoarseInterval.put(provider, null);
        updateProvidersLocked();
        Binder.restoreCallingIdentity(identity);
    }
}
 
Example 13
Source File: DisplayManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override // Binder call
public void dump(FileDescriptor fd, final PrintWriter pw, String[] args) {
    if (!DumpUtils.checkDumpPermission(mContext, TAG, pw)) return;

    final long token = Binder.clearCallingIdentity();
    try {
        dumpInternal(pw);
    } finally {
        Binder.restoreCallingIdentity(token);
    }
}
 
Example 14
Source File: StorageManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private int adjustAllocateFlags(int flags, int callingUid, String callingPackage) {
    // Require permission to allocate aggressively
    if ((flags & StorageManager.FLAG_ALLOCATE_AGGRESSIVE) != 0) {
        mContext.enforceCallingOrSelfPermission(
                android.Manifest.permission.ALLOCATE_AGGRESSIVE, TAG);
    }

    // Apps normally can't directly defy reserved space
    flags &= ~StorageManager.FLAG_ALLOCATE_DEFY_ALL_RESERVED;
    flags &= ~StorageManager.FLAG_ALLOCATE_DEFY_HALF_RESERVED;

    // However, if app is actively using the camera, then we're willing to
    // clear up to half of the reserved cache space, since the user might be
    // trying to capture an important memory.
    final AppOpsManager appOps = mContext.getSystemService(AppOpsManager.class);
    final long token = Binder.clearCallingIdentity();
    try {
        if (appOps.isOperationActive(AppOpsManager.OP_CAMERA, callingUid, callingPackage)) {
            Slog.d(TAG, "UID " + callingUid + " is actively using camera;"
                    + " letting them defy reserved cached data");
            flags |= StorageManager.FLAG_ALLOCATE_DEFY_HALF_RESERVED;
        }
    } finally {
        Binder.restoreCallingIdentity(token);
    }

    return flags;
}
 
Example 15
Source File: JobSchedulerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public JobInfo getPendingJob(int jobId) throws RemoteException {
    final int uid = Binder.getCallingUid();

    long ident = Binder.clearCallingIdentity();
    try {
        return JobSchedulerService.this.getPendingJob(uid, jobId);
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
 
Example 16
Source File: SnoozeHelper.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void scheduleRepost(String pkg, String key, int userId, long duration) {
    long identity = Binder.clearCallingIdentity();
    try {
        final PendingIntent pi = createPendingIntent(pkg, key, userId);
        mAm.cancel(pi);
        long time = SystemClock.elapsedRealtime() + duration;
        if (DEBUG) Slog.d(TAG, "Scheduling evaluate for " + new Date(time));
        mAm.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, time, pi);
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
}
 
Example 17
Source File: AndroidWordLevelSpellCheckerSession.java    From Android-Keyboard with Apache License 2.0 5 votes vote down vote up
@Override
public SuggestionsInfo onGetSuggestions(final TextInfo textInfo, final int suggestionsLimit) {
    long ident = Binder.clearCallingIdentity();
    try {
        return onGetSuggestionsInternal(textInfo, suggestionsLimit);
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
 
Example 18
Source File: SliceManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private boolean hasFullSliceAccess(String pkg, int userId) {
    long ident = Binder.clearCallingIdentity();
    try {
        boolean ret = isDefaultHomeApp(pkg, userId) || isAssistant(pkg, userId)
                || isGrantedFullAccess(pkg, userId);
        return ret;
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
 
Example 19
Source File: StatusBarManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void onNotificationExpansionChanged(String key, boolean userAction,
        boolean expanded) throws RemoteException {
    enforceStatusBarService();
    long identity = Binder.clearCallingIdentity();
    try {
        mNotificationDelegate.onNotificationExpansionChanged(
                key, userAction, expanded);
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
}
 
Example 20
Source File: RecentsAnimationController.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void setAnimationTargetsBehindSystemBars(boolean behindSystemBars)
        throws RemoteException {
    final long token = Binder.clearCallingIdentity();
    try {
        synchronized (mService.getWindowManagerLock()) {
            for (int i = mPendingAnimations.size() - 1; i >= 0; i--) {
                mPendingAnimations.get(i).mTask.setCanAffectSystemUiFlags(behindSystemBars);
            }
            mService.mWindowPlacerLocked.requestTraversal();
        }
    } finally {
        Binder.restoreCallingIdentity(token);
    }
}