Example usage for android.os Process myUid

List of usage examples for android.os Process myUid

Introduction

In this page you can find the example usage for android.os Process myUid.

Prototype

public static final int myUid() 

Source Link

Document

Returns the identifier of this process's uid.

Usage

From source file:Main.java

public static boolean checkPermission(Context context) {
    return context.checkPermission(Manifest.permission.CAMERA, Process.myPid(),
            Process.myUid()) == PackageManager.PERMISSION_GRANTED;
}

From source file:Main.java

public static boolean hasPermission(Context context, String permission) {
    if ((context == null) || (permission == null)) {
        return false;
    }//  w  w  w . j av  a  2  s.c  o  m
    return context.checkPermission(permission, Process.myPid(), Process.myUid()) == 0;
}

From source file:Main.java

public static boolean hasPermission(Context context, String permission) {
    return context.checkPermission(permission, Process.myPid(),
            Process.myUid()) == PackageManager.PERMISSION_GRANTED;
}

From source file:Main.java

public static boolean hasAppOp(Context context, String appOp) {
    final AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
    final int mode = appOpsManager.checkOpNoThrow(appOp, Process.myUid(), context.getPackageName());
    return mode == AppOpsManager.MODE_ALLOWED;
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.KITKAT)
public static boolean isAppOpsAllowed(Context context, String appOpsPermission) {
    AppOpsManager aom = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
    return aom.checkOpNoThrow(appOpsPermission, Process.myUid(),
            context.getPackageName()) == AppOpsManager.MODE_ALLOWED;
}

From source file:org.thoughtland.xlocation.UpdateService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    // Check if work
    if (intent == null) {
        stopSelf();/*from  ww w .ja  v a  2 s. c o m*/
        return 0;
    }

    // Flush
    if (cFlush.equals(intent.getAction())) {
        try {
            PrivacyService.getClient().flush();
        } catch (Throwable ex) {
            Util.bug(null, ex);
        }
        stopSelf();
        return 0;
    }

    // Update
    if (cUpdate.equals(intent.getAction())) {
        if (Util.hasProLicense(this) != null) {
            int userId = Util.getUserId(Process.myUid());
            boolean updates = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingUpdates, false);
            if (updates)
                new ActivityShare.UpdateTask(this).execute();
        }
        stopSelf();
        return 0;
    }

    // Check action
    Bundle extras = intent.getExtras();
    if (extras.containsKey(cAction)) {
        final int action = extras.getInt(cAction);
        Util.log(null, Log.WARN, "Service received action=" + action + " flags=" + flags);

        // Check service
        if (PrivacyService.getClient() == null) {
            Util.log(null, Log.ERROR, "Service not available");
            stopSelf();
            return 0;
        }

        // Start foreground service
        NotificationCompat.Builder builder = new NotificationCompat.Builder(UpdateService.this);
        builder.setSmallIcon(R.drawable.ic_launcher);
        builder.setContentTitle(getString(R.string.app_name));
        builder.setContentText(getString(R.string.msg_service));
        builder.setWhen(System.currentTimeMillis());
        builder.setAutoCancel(false);
        builder.setOngoing(true);
        Notification notification = builder.build();
        startForeground(Util.NOTIFY_SERVICE, notification);

        // Start worker
        mWorkerThread = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    // Check action
                    if (action == cActionBoot) {
                        // Boot received
                        migrate(UpdateService.this);
                        upgrade(UpdateService.this);
                        randomize(UpdateService.this);

                    } else if (action == cActionUpdated) {
                        // Self updated
                        upgrade(UpdateService.this);

                    } else
                        Util.log(null, Log.ERROR, "Unknown action=" + action);

                    // Done
                    stopForeground(true);
                    stopSelf();
                } catch (Throwable ex) {
                    Util.bug(null, ex);
                    // Leave service running
                }
            }

        });
        mWorkerThread.start();
    } else
        Util.log(null, Log.ERROR, "Action missing");

    return START_STICKY;
}

From source file:org.thoughtland.xlocation.Util.java

public static void log(XHook hook, int priority, String msg) {
    // Check if logging enabled
    int uid = Process.myUid();
    if (!mLogDetermined && uid > 0) {
        mLogDetermined = true;//from www.ja  v a2s . c  o m
        try {
            mLog = PrivacyManager.getSettingBool(0, PrivacyManager.cSettingLog, false);
        } catch (Throwable ignored) {
            mLog = false;
        }
    }

    // Log if enabled
    if (priority != Log.DEBUG && (priority == Log.INFO ? mLog : true))
        if (hook == null)
            Log.println(priority, "XLocation", msg);
        else
            Log.println(priority, String.format("XLocation/%s", hook.getClass().getSimpleName()), msg);

    // Report to service
    if (uid > 0 && priority == Log.ERROR)
        if (PrivacyService.isRegistered())
            PrivacyService.reportErrorInternal(msg);
        else
            try {
                IPrivacyService client = PrivacyService.getClient();
                if (client != null)
                    client.reportError(msg);
            } catch (RemoteException ignored) {
            }
}

From source file:biz.bokhorst.xprivacy.Util.java

public static void log(XHook hook, int priority, String msg) {
    // Check if logging enabled
    int uid = Process.myUid();
    if (!mLogDetermined && uid > 0) {
        mLogDetermined = true;//from  w  w  w .j a  va  2  s.c  om
        try {
            mLog = PrivacyManager.getSettingBool(0, PrivacyManager.cSettingLog, false);
        } catch (Throwable ignored) {
            mLog = false;
        }
    }

    // Log if enabled
    if (priority != Log.DEBUG && (priority == Log.INFO ? mLog : true))
        if (hook == null)
            Log.println(priority, "XPrivacy", msg);
        else
            Log.println(priority, String.format("XPrivacy/%s", hook.getClass().getSimpleName()), msg);

    // Report to service
    if (uid > 0 && priority == Log.ERROR)
        if (PrivacyService.isRegistered())
            PrivacyService.reportErrorInternal(msg);
        else
            try {
                IPrivacyService client = PrivacyService.getClient();
                if (client != null)
                    client.reportError(msg);
            } catch (RemoteException ignored) {
            }
}

From source file:org.mariotaku.twidere.util.PermissionsManager.java

public boolean checkPermission(final int uid, final String... requiredPermissions) {
    if (requiredPermissions == null || requiredPermissions.length == 0)
        return true;
    if (Process.myUid() == uid)
        return true;
    if (checkSignature(uid))
        return true;
    final String pname = getPackageNameByUid(uid);
    final String[] permissions = getPermissions(pname);
    return TwidereArrayUtils.contains(permissions, requiredPermissions);
}

From source file:org.thoughtland.xlocation.Util.java

public static void bug(XHook hook, Throwable ex) {
    int priority;
    if (ex instanceof ActivityShare.AbortException)
        priority = Log.WARN;//from w w w .  j  a va2s. co m
    else if (ex instanceof ActivityShare.ServerException)
        priority = Log.WARN;
    else if (ex instanceof ConnectTimeoutException)
        priority = Log.WARN;
    else if (ex instanceof FileNotFoundException)
        priority = Log.WARN;
    else if (ex instanceof HttpHostConnectException)
        priority = Log.WARN;
    else if (ex instanceof NoClassDefFoundError)
        priority = Log.WARN;
    else if (ex instanceof OutOfMemoryError)
        priority = Log.WARN;
    else if (ex instanceof RuntimeException)
        priority = Log.WARN;
    else if (ex instanceof SecurityException)
        priority = Log.WARN;
    else if (ex instanceof SocketTimeoutException)
        priority = Log.WARN;
    else if (ex instanceof SSLPeerUnverifiedException)
        priority = Log.WARN;
    else if (ex instanceof TransactionTooLargeException)
        priority = Log.WARN;
    else if (ex instanceof UnknownHostException)
        priority = Log.WARN;
    else
        priority = Log.ERROR;

    boolean xlocation = false;
    for (StackTraceElement frame : ex.getStackTrace())
        if (frame.getClassName() != null && frame.getClassName().startsWith("org.thoughtland.xlocation")) {
            xlocation = true;
            break;
        }
    if (!xlocation)
        priority = Log.WARN;

    log(hook, priority, ex.toString() + " uid=" + Process.myUid() + "\n" + Log.getStackTraceString(ex));
}