下面列出了android.os.Binder#restoreCallingIdentity ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
}
@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;
}
@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;
}
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);
}
}
@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);
}
}
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());
}
}
}
}
@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);
}
}
@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);
}
}
@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);
}
}
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);
}
}
@Override
public SuggestionsInfo onGetSuggestions(final TextInfo textInfo, final int suggestionsLimit) {
long ident = Binder.clearCallingIdentity();
try {
return onGetSuggestionsInternal(textInfo, suggestionsLimit);
} finally {
Binder.restoreCallingIdentity(ident);
}
}
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);
}
}
@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);
}
}
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;
}
@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);
}
}
@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);
}
}
@Override
public void cancelDragAndDrop(IBinder dragToken) {
final long ident = Binder.clearCallingIdentity();
try {
mDragDropController.cancelDragAndDrop(dragToken);
} finally {
Binder.restoreCallingIdentity(ident);
}
}
@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);
}
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");
}
}
}
@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);
}
}