當前位置: 首頁>>代碼示例>>Java>>正文


Java Binder類代碼示例

本文整理匯總了Java中android.os.Binder的典型用法代碼示例。如果您正苦於以下問題:Java Binder類的具體用法?Java Binder怎麽用?Java Binder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Binder類屬於android.os包,在下文中一共展示了Binder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: query

import android.os.Binder; //導入依賴的package包/類
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
        throws Exception {
    List<String> segments = uri.getPathSegments();
    int accountId = Integer.parseInt(segments.get(1));

    /*
     * This method below calls Account.getStats() which uses EmailProvider to do its work.
     * For this to work we need to clear the calling identity. Otherwise accessing
     * EmailProvider will fail because it's not exported so third-party apps can't access it
     * directly.
     */
    long identityToken = Binder.clearCallingIdentity();
    try {
        return getAccountUnread(accountId);
    } finally {
        Binder.restoreCallingIdentity(identityToken);
    }
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:20,代碼來源:MessageProvider.java

示例2: checkOp

import android.os.Binder; //導入依賴的package包/類
@TargetApi(19)
private static boolean checkOp(Context context, int op) {
    final int version = Build.VERSION.SDK_INT;
    if (version >= Build.VERSION_CODES.KITKAT) {
        AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        try {
            Method method = manager.getClass().getDeclaredMethod("checkOp", int.class, int.class, String.class);
            int property = (Integer) method.invoke(manager, op,
                    Binder.getCallingUid(), context.getPackageName());
            return AppOpsManager.MODE_ALLOWED == property;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return false;
}
 
開發者ID:QMUI,項目名稱:QMUI_Android,代碼行數:17,代碼來源:QMUIDeviceHelper.java

示例3: after

import android.os.Binder; //導入依賴的package包/類
@Override
protected void after(XParam param) throws Throwable {
	String key = (param.args.length > 0 ? (String) param.args[0] : null);
	if (key != null)
		if (mPropertyName.startsWith("%") ? key.contains(mPropertyName.substring(1)) : key.equals(mPropertyName))
			if (mMethod == Methods.get) {
				if (param.getResult() != null && isRestrictedExtra(param, mPropertyName, key))
					param.setResult(PrivacyManager.getDefacedProp(Binder.getCallingUid(), mPropertyName));

			} else if (param.args.length > 1) {
				if (isRestrictedExtra(param, mPropertyName, key))
					param.setResult(param.args[1]);

			} else
				Util.log(this, Log.WARN, "Unknown method=" + param.method.getName());
}
 
開發者ID:ukanth,項目名稱:XPrivacy,代碼行數:17,代碼來源:XSystemProperties.java

示例4: checkOp

import android.os.Binder; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.KITKAT)
private static boolean checkOp(Context context, int op) {
    final int version = Build.VERSION.SDK_INT;
    if (version >= 19) {
        AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        try {
            Class clazz = AppOpsManager.class;
            Method method = clazz.getDeclaredMethod("checkOp", int.class, int.class, String.class);
            return AppOpsManager.MODE_ALLOWED == (int)method.invoke(manager, op, Binder.getCallingUid(), context.getPackageName());
        } catch (Exception e) {
            Log.e(TAG, Log.getStackTraceString(e));
        }
    } else {
        Log.e(TAG, "Below API 19 cannot invoke!");
    }
    return false;
}
 
開發者ID:Zyj163,項目名稱:yyox,代碼行數:18,代碼來源:MeizuUtils.java

示例5: queryChildDocuments

import android.os.Binder; //導入依賴的package包/類
@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;
}
 
開發者ID:medalionk,項目名稱:simple-share-android,代碼行數:27,代碼來源:DownloadStorageProvider.java

示例6: createService

import android.os.Binder; //導入依賴的package包/類
private static void createService(Service service, Intent intent) {
    if (intent.hasExtra(ApkConstant.EXTRA_APK_PATH)) {
        String apkPath = ApkComponentModifier.getPath(intent);
        String className = ApkComponentModifier.getClassName(intent);
        String key = ApkComponentModifier.getKey(intent);
        if (!mRealServices.containsKey(service) || !mRealServices.get(service).containsKey(key)) {
            try {
                Object realToken = new Binder();
                Service rawService = handleCreateService(realToken, service, apkPath, className);
                if (mRealServices.containsKey(service)) {
                    mRealServices.get(service).put(key, rawService);
                } else {
                    Map<String, Service> serviceMap = new HashMap<>();
                    serviceMap.put(key, rawService);
                    mRealServices.put(service, serviceMap);
                }
            } catch (Exception e) {
            }
        }
    }
}
 
開發者ID:LiangMaYong,項目名稱:android-apkbox,代碼行數:22,代碼來源:HookService_Manager.java

示例7: asyncGetService

import android.os.Binder; //導入依賴的package包/類
@Override
public void asyncGetService(String serviceName, IServiceCallback callback)
		throws RemoteException {
	LogControler.info("ServiceManagerServer", "[svcmgr server] asyncGetService name = " + serviceName + " , callingpid = " + Binder.getCallingPid());
	IBinder service = clientServiceContainer.get(serviceName);
	
	if(service == null) {
		service = BinderQuerier.query(serviceName);
	}

	if(service == null){
		asyncClientServiceContainer.put(serviceName, IServiceCallbackProxy.proxy(serviceName,callback));
	} else {
		callback.callback(service);
	}
	
}
 
開發者ID:devyok,項目名稱:IPCServiceManager,代碼行數:18,代碼來源:ServiceManagerServer.java

示例8: checkOp

import android.os.Binder; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.KITKAT)
private static boolean checkOp(Context context, int op) {
    final int version = Build.VERSION.SDK_INT;
    if (version >= 19) {
        AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        try {
            Class clazz = AppOpsManager.class;
            Method method = clazz.getDeclaredMethod("checkOp", int.class, int.class, String.class);
            return AppOpsManager.MODE_ALLOWED == (int)method.invoke(manager, op, Binder.getCallingUid(), context.getPackageName());
        } catch (Exception e) {
            Log.e(TAG, Log.getStackTraceString(e));
        }
    } else {
        Log.e("", "Below API 19 cannot invoke!");
    }
    return false;
}
 
開發者ID:Zyj163,項目名稱:yyox,代碼行數:18,代碼來源:QikuUtils.java

示例9: checkOp

import android.os.Binder; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.KITKAT)
private static boolean checkOp(Context context, int op) {
    final int version = Build.VERSION.SDK_INT;
    if (version >= 19) {
        AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        try {
            Class clazz = AppOpsManager.class;
            Method method = clazz.getDeclaredMethod("checkOp", int.class, int.class, String.class);
            return AppOpsManager.MODE_ALLOWED == (int) method.invoke(manager, op, Binder.getCallingUid(), context.getPackageName());
        } catch (Exception e) {
            Log.e(TAG, Log.getStackTraceString(e));
        }
    } else {
        Log.e(TAG, "Below API 19 cannot invoke!");
    }
    return false;
}
 
開發者ID:Zyj163,項目名稱:yyox,代碼行數:18,代碼來源:HuaweiUtils.java

示例10: openDocument

import android.os.Binder; //導入依賴的package包/類
@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);
    }
}
 
開發者ID:medalionk,項目名稱:simple-share-android,代碼行數:19,代碼來源:NonMediaDocumentsProvider.java

示例11: addService

import android.os.Binder; //導入依賴的package包/類
@Override
public void addService(String serviceName, IBinder service)
		throws RemoteException {

	LogControler.info("ServiceManagerServer", "[svcmgr server] addService name = " + serviceName + " , service = " + service+ " , callingpid = " + Binder.getCallingPid());

	service.linkToDeath(new BinderServiceDeathRecipient(serviceName),0);
	clientServiceContainer.put(serviceName, service);

	//查看是否有listen這個服務的
	IServiceCallbackProxy serviceCallback = asyncClientServiceContainer.get(serviceName);

	if(serviceCallback!=null){
		try {
			LogControler.info("ServiceManagerServer", "[svcmgr server] addService onReady");
			serviceCallback.callback(service);
		} catch(Exception e){
			e.printStackTrace();
		}
	} else {
		LogControler.info("ServiceManagerServer", "[svcmgr server] addService serviceCallback not found");
	}
}
 
開發者ID:devyok,項目名稱:IPCServiceManager,代碼行數:24,代碼來源:ServiceManagerServer.java

示例12: after

import android.os.Binder; //導入依賴的package包/類
@Override
protected void after(XParam param) throws Throwable {
	if (mMethod == Methods.getDetailedState) {
		if (param.getResult() != null && isRestricted(param))
			param.setResult(NetworkInfo.DetailedState.DISCONNECTED);

	} else if (mMethod == Methods.getExtraInfo) {
		if (param.getResult() != null && isRestricted(param))
			param.setResult(PrivacyManager.getDefacedProp(Binder.getCallingUid(), "ExtraInfo"));

	} else if (mMethod == Methods.getState) {
		if (param.getResult() != null && isRestricted(param))
			param.setResult(NetworkInfo.State.DISCONNECTED);

	} else if (mMethod == Methods.isConnected || mMethod == Methods.isConnectedOrConnecting) {
		if (isRestricted(param))
			param.setResult(false);

	} else
		Util.log(this, Log.WARN, "Unknown method=" + param.method.getName());
}
 
開發者ID:ukanth,項目名稱:XPrivacy,代碼行數:22,代碼來源:XNetworkInfo.java

示例13: deleteDocument

import android.os.Binder; //導入依賴的package包/類
@Override
public void deleteDocument(String docId) throws FileNotFoundException {
	final String packageName = getPackageForDocId(docId);
    final long token = Binder.clearCallingIdentity();
    try {
    	if (docId.startsWith(ROOT_ID_USER_APP)) {
PackageManagerUtils.uninstallApp(getContext(), packageName);
    	}
    	else if(docId.startsWith(ROOT_ID_PROCESS)) {
    		activityManager.killBackgroundProcesses(getPackageForDocId(docId));
    	}
    	notifyDocumentsChanged(docId);
    } finally {
        Binder.restoreCallingIdentity(token);
    }
}
 
開發者ID:gigabytedevelopers,項目名稱:FireFiles,代碼行數:17,代碼來源:AppsProvider.java

示例14: queryChildDocumentsForManage

import android.os.Binder; //導入依賴的package包/類
@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;
}
 
開發者ID:medalionk,項目名稱:simple-share-android,代碼行數:23,代碼來源:DownloadStorageProvider.java

示例15: queryChildDocuments

import android.os.Binder; //導入依賴的package包/類
@Override
public Cursor queryChildDocuments(String docId, String[] projection, String sortOrder)
        throws FileNotFoundException {
    final ContentResolver resolver = getContext().getContentResolver();
    final MatrixCursor result = new MatrixCursor(resolveDocumentProjection(projection));
    final Ident ident = getIdentForDocId(docId);

    final long token = Binder.clearCallingIdentity();
    Cursor cursor = null;
    try {
        if (TYPE_DOCUMENT_ROOT.equals(ident.type)) {
            queryFile(resolver, cursor, result, DOCUMENT_MIMES, "text");
        } else if (TYPE_ARCHIVE_ROOT.equals(ident.type)) {
            queryFile(resolver, cursor, result, ARCHIVE_MIMES);
        } else if (TYPE_APK_ROOT.equals(ident.type)) {
            queryFile(resolver, cursor, result, APK_MIMES);
        } else {
            throw new UnsupportedOperationException("Unsupported document " + docId);
        }
    } finally {
        IoUtils.closeQuietly(cursor);
        Binder.restoreCallingIdentity(token);
    }
    return result;
}
 
開發者ID:kranthi0987,項目名稱:easyfilemanager,代碼行數:26,代碼來源:NonMediaDocumentsProvider.java


注:本文中的android.os.Binder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。