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:org.chromium.chrome.browser.bookmark.ManageBookmarkActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try {//from   w  w w.  j  a v  a2  s  .  com
        if (getApplication() instanceof ChromeApplication) {
            ((ChromeApplication) getApplication()).startBrowserProcessesAndLoadLibrariesSync(true);
        }
    } catch (ProcessInitException e) {
        Log.e(TAG, "Unable to load native library.", e);
        ChromeApplication.reportStartupErrorAndExit(e);
        return;
    }
    if (!DeviceFormFactor.isTablet(this)) {
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
                | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    }

    if (savedInstanceState == null) {
        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        fragmentTransaction.add(android.R.id.content, generateBaseFragment(), BASE_ADD_EDIT_FRAGMENT_TAG);
        fragmentTransaction.commit();
    } else {
        initializeFragmentState();
    }

    // When adding or removing fragments, ensure the keyboard is hidden if visible as the
    // editing fields are no longer on the screen.
    getFragmentManager().addOnBackStackChangedListener(new OnBackStackChangedListener() {
        @Override
        public void onBackStackChanged() {
            UiUtils.hideKeyboard(findViewById(android.R.id.content));
        }
    });
    if (checkPermission(Manifest.permission.NFC, Process.myPid(),
            Process.myUid()) == PackageManager.PERMISSION_GRANTED) {
        NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
        if (nfcAdapter != null)
            nfcAdapter.setNdefPushMessage(null, this);
    }
}

From source file:org.chromium.chrome.browser.preferences.Preferences.java

@SuppressFBWarnings("DM_EXIT")
@SuppressLint("InlinedApi")
@Override/*from   ww  w. ja va  2  s .c o  m*/
protected void onCreate(Bundle savedInstanceState) {
    ensureActivityNotExported();

    // The browser process must be started here because this Activity may be started explicitly
    // from Android notifications, when Android is restoring Preferences after Chrome was
    // killed, or for tests. This should happen before super.onCreate() because it might
    // recreate a fragment, and a fragment might depend on the native library.
    try {
        ((ChromeApplication) getApplication()).startBrowserProcessesAndLoadLibrariesSync(true);
    } catch (ProcessInitException e) {
        Log.e(TAG, "Failed to start browser process.", e);
        // This can only ever happen, if at all, when the activity is started from an Android
        // notification (or in tests). As such we don't want to show an error messsage to the
        // user. The application is completely broken at this point, so close it down
        // completely (not just the activity).
        System.exit(-1);
        return;
    }

    super.onCreate(savedInstanceState);

    mIsNewlyCreated = savedInstanceState == null;

    String initialFragment = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
    Bundle initialArguments = getIntent().getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
    boolean displayHomeAsUp = getIntent().getBooleanExtra(EXTRA_DISPLAY_HOME_AS_UP, true);

    if (displayHomeAsUp)
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // This must be called before the fragment transaction below.
    workAroundPlatformBugs();

    // If savedInstanceState is non-null, then the activity is being
    // recreated and super.onCreate() has already recreated the fragment.
    if (savedInstanceState == null) {
        if (initialFragment == null)
            initialFragment = MainPreferences.class.getName();
        Fragment fragment = Fragment.instantiate(this, initialFragment, initialArguments);
        getFragmentManager().beginTransaction().replace(android.R.id.content, fragment).commit();
    }

    if (checkPermission(Manifest.permission.NFC, Process.myPid(),
            Process.myUid()) == PackageManager.PERMISSION_GRANTED) {
        // Disable Android Beam on JB and later devices.
        // In ICS it does nothing - i.e. we will send a Play Store link if NFC is used.
        NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
        if (nfcAdapter != null)
            nfcAdapter.setNdefPushMessage(null, this);
    }

    Resources res = getResources();
    ApiCompatibilityUtils.setTaskDescription(this, res.getString(R.string.app_name),
            BitmapFactory.decodeResource(res, R.mipmap.app_icon),
            ApiCompatibilityUtils.getColor(res, R.color.default_primary_color));
}

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

private static void migrate(Context context) throws IOException, RemoteException {
    int first = 0;
    String format = context.getString(R.string.msg_migrating);
    List<ApplicationInfo> listApp = context.getPackageManager().getInstalledApplications(0);

    // Start migrate
    PrivacyProvider.migrateLegacy(context);

    // Migrate global settings
    PrivacyManager.setSettingList(PrivacyProvider.migrateSettings(context, 0));
    PrivacyProvider.finishMigrateSettings(0);

    // Migrate application settings/restrictions
    for (int i = 1; i <= listApp.size(); i++) {
        int uid = listApp.get(i - 1).uid;
        // Settings
        List<PSetting> listSetting = PrivacyProvider.migrateSettings(context, uid);
        PrivacyManager.setSettingList(listSetting);
        PrivacyProvider.finishMigrateSettings(uid);

        // Restrictions
        List<PRestriction> listRestriction = PrivacyProvider.migrateRestrictions(context, uid);
        PrivacyManager.setRestrictionList(listRestriction);
        PrivacyProvider.finishMigrateRestrictions(uid);

        if (first == 0)
            if (listSetting.size() > 0 || listRestriction.size() > 0)
                first = i;/* www  .  ja  v a2  s.c  om*/
        if (first > 0 && first < listApp.size())
            notifyProgress(context, Util.NOTIFY_MIGRATE, format, 100 * (i - first) / (listApp.size() - first));
    }
    if (first == 0)
        Util.log(null, Log.WARN, "Nothing to migrate");

    // Complete migration
    int userId = Util.getUserId(Process.myUid());
    PrivacyService.getClient()
            .setSetting(new PSetting(userId, "", PrivacyManager.cSettingMigrated, Boolean.toString(true)));
}

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

public static void bug(XHook hook, Throwable ex) {
    if (ex instanceof InvocationTargetException) {
        InvocationTargetException exex = (InvocationTargetException) ex;
        if (exex.getTargetException() != null)
            ex = exex.getTargetException();
    }/*from  w ww  . jav a2s .  co  m*/

    int priority;
    if (ex instanceof ActivityShare.AbortException)
        priority = Log.WARN;
    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 NameNotFoundException)
        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 StackOverflowError)
        priority = Log.WARN;
    else if (ex instanceof TransactionTooLargeException)
        priority = Log.WARN;
    else if (ex instanceof UnknownHostException)
        priority = Log.WARN;
    else if (ex instanceof UnsatisfiedLinkError)
        priority = Log.WARN;
    else
        priority = Log.ERROR;

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

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

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

private static void upgrade(Context context) throws NameNotFoundException {
    // Get previous version number
    int userId = Util.getUserId(Process.myUid());
    Version currentVersion = new Version(Util.getSelfVersionName(context));
    Version storedVersion = new Version(
            PrivacyManager.getSetting(userId, PrivacyManager.cSettingVersion, "0.0"));
    boolean dangerous = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingDangerous, false);

    // Check if upgrade needed
    if (storedVersion.compareTo(new Version("0.0")) != 0 && currentVersion.compareTo(storedVersion) > 0) {
        Util.log(null, Log.WARN, "Starting upgrade from version " + storedVersion + " to version "
                + currentVersion + " dangerous=" + dangerous);

        // Upgrade packages
        int first = 0;
        String format = context.getString(R.string.msg_upgrading);
        List<ApplicationInfo> listApp = context.getPackageManager().getInstalledApplications(0);

        for (int i = 1; i <= listApp.size(); i++) {
            int uid = listApp.get(i - 1).uid;
            List<PRestriction> listRestriction = getUpgradeWork(storedVersion, uid, dangerous);
            PrivacyManager.setRestrictionList(listRestriction);

            // Reset on demand for system applications
            if (new ApplicationInfoEx(context, listApp.get(i - 1).uid).isSystem())
                if (storedVersion.compareTo(new Version("2.0.38")) < 0)
                    if (PrivacyManager.getSettingBool(listApp.get(i - 1).uid, PrivacyManager.cSettingOnDemand,
                            false)) {/*from   w w  w  . j  a  va 2s  .  co  m*/
                        Util.log(null, Log.WARN, "Disabling on demand for uid=" + listApp.get(i - 1).uid);
                        PrivacyManager.setSetting(listApp.get(i - 1).uid, PrivacyManager.cSettingOnDemand,
                                null);
                    }

            if (first == 0)
                if (listRestriction.size() > 0)
                    first = i;
            if (first > 0 && first < listApp.size())
                notifyProgress(context, Util.NOTIFY_UPGRADE, format,
                        100 * (i - first) / (listApp.size() - first));
        }
        if (first == 0)
            Util.log(null, Log.WARN,
                    "Nothing to upgrade from version " + storedVersion + " to " + currentVersion);

        // Remove legacy setting
        if (dangerous)
            PrivacyManager.setSetting(userId, PrivacyManager.cSettingDangerous, null);

        // Resolve quirk
        if (storedVersion.compareTo(new Version("2.99.28")) < 0)
            if (!PrivacyManager.getSettingBool(0, PrivacyManager.cSettingNoResolve, false)) {
                Util.log(null, Log.WARN, "Enabling quirk resolve");
                PrivacyManager.setSetting(0, PrivacyManager.cSettingResolve, Boolean.toString(true));
            }

        // Wipe template
        if (storedVersion.compareTo(new Version("2.0.34")) < 0)
            for (PSetting setting : PrivacyManager.getSettingList(0, null))
                if (Meta.cTypeTemplate.equals(setting.type)) {
                    Util.log(null, Log.WARN, "Deleting " + setting);
                    PrivacyManager.setSetting(setting.uid, setting.type, setting.name, null);
                }
    } else
        Util.log(null, Log.WARN, "No upgrade from version " + storedVersion + " to " + currentVersion);

    // Set new version number
    if (currentVersion.compareTo(storedVersion) > 0)
        PrivacyManager.setSetting(userId, PrivacyManager.cSettingVersion, currentVersion.toString());

    // Cleanup
    PrivacyManager.removeLegacySalt(userId);
}

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

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final int userId = Util.getUserId(Process.myUid());

    // Check privacy service client
    if (!PrivacyService.checkClient())
        return;/*from   ww  w.j  a  v a  2  s .c  o  m*/

    // Set layout
    setContentView(R.layout.restrictionlist);

    // Get arguments
    Bundle extras = getIntent().getExtras();
    if (extras == null) {
        finish();
        return;
    }

    int uid = extras.getInt(cUid);
    String restrictionName = (extras.containsKey(cRestrictionName) ? extras.getString(cRestrictionName) : null);
    String methodName = (extras.containsKey(cMethodName) ? extras.getString(cMethodName) : null);

    // Get app info
    mAppInfo = new ApplicationInfoEx(this, uid);
    if (mAppInfo.getPackageName().size() == 0) {
        finish();
        return;
    }

    // Set title
    setTitle(String.format("%s - %s", getString(R.string.app_name),
            TextUtils.join(", ", mAppInfo.getApplicationName())));

    // Handle info click
    ImageView imgInfo = (ImageView) findViewById(R.id.imgInfo);
    imgInfo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // Packages can be selected on the web site
            Util.viewUri(ActivityApp.this,
                    Uri.parse(String.format(ActivityShare.getBaseURL(ActivityApp.this) + "?package_name=%s",
                            mAppInfo.getPackageName().get(0))));
        }
    });

    // Display app name
    TextView tvAppName = (TextView) findViewById(R.id.tvApp);
    tvAppName.setText(mAppInfo.toString());

    // Background color
    if (mAppInfo.isSystem()) {
        LinearLayout llInfo = (LinearLayout) findViewById(R.id.llInfo);
        llInfo.setBackgroundColor(getResources().getColor(getThemed(R.attr.color_dangerous)));
    }

    // Display app icon
    final ImageView imgIcon = (ImageView) findViewById(R.id.imgIcon);
    imgIcon.setImageDrawable(mAppInfo.getIcon(this));

    // Handle icon click
    imgIcon.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            openContextMenu(imgIcon);
        }
    });

    // Display on-demand state
    final ImageView imgCbOnDemand = (ImageView) findViewById(R.id.imgCbOnDemand);
    if (PrivacyManager.isApplication(mAppInfo.getUid())
            && PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingOnDemand, true)) {
        boolean ondemand = PrivacyManager.getSettingBool(-mAppInfo.getUid(), PrivacyManager.cSettingOnDemand,
                false);
        imgCbOnDemand.setImageBitmap(ondemand ? getOnDemandCheckBox() : getOffCheckBox());

        imgCbOnDemand.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                boolean ondemand = !PrivacyManager.getSettingBool(-mAppInfo.getUid(),
                        PrivacyManager.cSettingOnDemand, false);
                PrivacyManager.setSetting(mAppInfo.getUid(), PrivacyManager.cSettingOnDemand,
                        Boolean.toString(ondemand));
                imgCbOnDemand.setImageBitmap(ondemand ? getOnDemandCheckBox() : getOffCheckBox());
                if (mPrivacyListAdapter != null)
                    mPrivacyListAdapter.notifyDataSetChanged();
            }
        });
    } else
        imgCbOnDemand.setVisibility(View.GONE);

    // Display restriction state
    swEnabled = (Switch) findViewById(R.id.swEnable);
    swEnabled.setChecked(
            PrivacyManager.getSettingBool(mAppInfo.getUid(), PrivacyManager.cSettingRestricted, true));
    swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            PrivacyManager.setSetting(mAppInfo.getUid(), PrivacyManager.cSettingRestricted,
                    Boolean.toString(isChecked));
            if (mPrivacyListAdapter != null)
                mPrivacyListAdapter.notifyDataSetChanged();
            imgCbOnDemand.setEnabled(isChecked);
        }
    });
    imgCbOnDemand.setEnabled(swEnabled.isChecked());

    // Add context menu to icon
    registerForContextMenu(imgIcon);

    // Check if internet access
    if (!mAppInfo.hasInternet(this)) {
        ImageView imgInternet = (ImageView) findViewById(R.id.imgInternet);
        imgInternet.setVisibility(View.INVISIBLE);
    }

    // Check if frozen
    if (!mAppInfo.isFrozen(this)) {
        ImageView imgFrozen = (ImageView) findViewById(R.id.imgFrozen);
        imgFrozen.setVisibility(View.INVISIBLE);
    }

    // Display version
    TextView tvVersion = (TextView) findViewById(R.id.tvVersion);
    tvVersion.setText(TextUtils.join(", ", mAppInfo.getPackageVersionName(this)));

    // Display package name
    TextView tvPackageName = (TextView) findViewById(R.id.tvPackageName);
    tvPackageName.setText(TextUtils.join(", ", mAppInfo.getPackageName()));

    // Fill privacy list view adapter
    final ExpandableListView lvRestriction = (ExpandableListView) findViewById(R.id.elvRestriction);
    lvRestriction.setGroupIndicator(null);
    mPrivacyListAdapter = new RestrictionAdapter(R.layout.restrictionentry, mAppInfo, restrictionName,
            methodName);
    lvRestriction.setAdapter(mPrivacyListAdapter);
    if (restrictionName != null) {
        int groupPosition = new ArrayList<String>(PrivacyManager.getRestrictions(this).values())
                .indexOf(restrictionName);
        lvRestriction.expandGroup(groupPosition);
        lvRestriction.setSelectedGroup(groupPosition);
        if (methodName != null) {
            int childPosition = PrivacyManager.getHooks(restrictionName)
                    .indexOf(new Hook(restrictionName, methodName));
            lvRestriction.setSelectedChild(groupPosition, childPosition, true);
        }
    }

    // Listen for package add/remove
    IntentFilter iff = new IntentFilter();
    iff.addAction(Intent.ACTION_PACKAGE_REMOVED);
    iff.addDataScheme("package");
    registerReceiver(mPackageChangeReceiver, iff);
    mPackageChangeReceiverRegistered = true;

    // Up navigation
    getActionBar().setDisplayHomeAsUpEnabled(true);

    // Tutorial
    if (!PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingTutorialDetails, false)) {
        ((ScrollView) findViewById(R.id.svTutorialHeader)).setVisibility(View.VISIBLE);
        ((ScrollView) findViewById(R.id.svTutorialDetails)).setVisibility(View.VISIBLE);
    }
    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ViewParent parent = view.getParent();
            while (!parent.getClass().equals(ScrollView.class))
                parent = parent.getParent();
            ((View) parent).setVisibility(View.GONE);
            PrivacyManager.setSetting(userId, PrivacyManager.cSettingTutorialDetails, Boolean.TRUE.toString());
        }
    };
    ((Button) findViewById(R.id.btnTutorialHeader)).setOnClickListener(listener);
    ((Button) findViewById(R.id.btnTutorialDetails)).setOnClickListener(listener);

    // Process actions
    if (extras.containsKey(cAction)) {
        NotificationManager notificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        notificationManager.cancel(mAppInfo.getUid());
        if (extras.getInt(cAction) == cActionClear)
            optionClear();
        else if (extras.getInt(cAction) == cActionSettings)
            optionSettings();
    }

    // Annotate
    Meta.annotate(this);
}

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

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final int userId = Util.getUserId(Process.myUid());

    // Check privacy service client
    if (!PrivacyService.checkClient())
        return;/*  w w w. j av  a  2  s.  co  m*/

    // Set layout
    setContentView(R.layout.restrictionlist);

    // Get arguments
    Bundle extras = getIntent().getExtras();
    if (extras == null) {
        finish();
        return;
    }

    int uid = extras.getInt(cUid);
    String restrictionName = (extras.containsKey(cRestrictionName) ? extras.getString(cRestrictionName) : null);
    String methodName = (extras.containsKey(cMethodName) ? extras.getString(cMethodName) : null);

    // Get app info
    mAppInfo = new ApplicationInfoEx(this, uid);
    if (mAppInfo.getPackageName().size() == 0) {
        finish();
        return;
    }

    // Set sub title
    getActionBar().setSubtitle(TextUtils.join(", ", mAppInfo.getApplicationName()));

    // Handle info click
    ImageView imgInfo = (ImageView) findViewById(R.id.imgInfo);
    imgInfo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // Packages can be selected on the web site
            Util.viewUri(ActivityApp.this,
                    Uri.parse(String.format(ActivityShare.getBaseURL() + "?package_name=%s",
                            mAppInfo.getPackageName().get(0))));
        }
    });

    // Display app name
    TextView tvAppName = (TextView) findViewById(R.id.tvApp);
    tvAppName.setText(mAppInfo.toString());

    // Background color
    if (mAppInfo.isSystem()) {
        LinearLayout llInfo = (LinearLayout) findViewById(R.id.llInfo);
        llInfo.setBackgroundColor(getResources().getColor(getThemed(R.attr.color_dangerous)));
    }

    // Display app icon
    final ImageView imgIcon = (ImageView) findViewById(R.id.imgIcon);
    imgIcon.setImageDrawable(mAppInfo.getIcon(this));

    // Handle icon click
    imgIcon.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            openContextMenu(imgIcon);
        }
    });

    // Display on-demand state
    final ImageView imgCbOnDemand = (ImageView) findViewById(R.id.imgCbOnDemand);
    boolean isApp = PrivacyManager.isApplication(mAppInfo.getUid());
    boolean odSystem = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingOnDemandSystem, false);
    boolean gondemand = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingOnDemand, true);
    if ((isApp || odSystem) && gondemand) {
        boolean ondemand = PrivacyManager.getSettingBool(-mAppInfo.getUid(), PrivacyManager.cSettingOnDemand,
                false);
        imgCbOnDemand.setImageBitmap(ondemand ? getOnDemandCheckBox() : getOffCheckBox());

        imgCbOnDemand.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                boolean ondemand = !PrivacyManager.getSettingBool(-mAppInfo.getUid(),
                        PrivacyManager.cSettingOnDemand, false);
                PrivacyManager.setSetting(mAppInfo.getUid(), PrivacyManager.cSettingOnDemand,
                        Boolean.toString(ondemand));
                imgCbOnDemand.setImageBitmap(ondemand ? getOnDemandCheckBox() : getOffCheckBox());
                if (mPrivacyListAdapter != null)
                    mPrivacyListAdapter.notifyDataSetChanged();
            }
        });
    } else
        imgCbOnDemand.setVisibility(View.GONE);

    // Display restriction state
    swEnabled = (Switch) findViewById(R.id.swEnable);
    swEnabled.setChecked(
            PrivacyManager.getSettingBool(mAppInfo.getUid(), PrivacyManager.cSettingRestricted, true));
    swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            PrivacyManager.setSetting(mAppInfo.getUid(), PrivacyManager.cSettingRestricted,
                    Boolean.toString(isChecked));
            if (mPrivacyListAdapter != null)
                mPrivacyListAdapter.notifyDataSetChanged();
            imgCbOnDemand.setEnabled(isChecked);
        }
    });
    imgCbOnDemand.setEnabled(swEnabled.isChecked());

    // Add context menu to icon
    registerForContextMenu(imgIcon);

    // Check if internet access
    if (!mAppInfo.hasInternet(this)) {
        ImageView imgInternet = (ImageView) findViewById(R.id.imgInternet);
        imgInternet.setVisibility(View.INVISIBLE);
    }

    // Check if frozen
    if (!mAppInfo.isFrozen(this)) {
        ImageView imgFrozen = (ImageView) findViewById(R.id.imgFrozen);
        imgFrozen.setVisibility(View.INVISIBLE);
    }

    // Display version
    TextView tvVersion = (TextView) findViewById(R.id.tvVersion);
    tvVersion.setText(TextUtils.join(", ", mAppInfo.getPackageVersionName(this)));

    // Display package name
    TextView tvPackageName = (TextView) findViewById(R.id.tvPackageName);
    tvPackageName.setText(TextUtils.join(", ", mAppInfo.getPackageName()));

    // Fill privacy expandable list view adapter
    final ExpandableListView elvRestriction = (ExpandableListView) findViewById(R.id.elvRestriction);
    elvRestriction.setGroupIndicator(null);
    mPrivacyListAdapter = new RestrictionAdapter(this, R.layout.restrictionentry, mAppInfo, restrictionName,
            methodName);
    elvRestriction.setAdapter(mPrivacyListAdapter);

    // Listen for group expand
    elvRestriction.setOnGroupExpandListener(new OnGroupExpandListener() {
        @Override
        public void onGroupExpand(final int groupPosition) {
            if (!PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingMethodExpert, false)) {
                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityApp.this);
                alertDialogBuilder.setTitle(R.string.app_name);
                alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
                alertDialogBuilder.setMessage(R.string.msg_method_expert);
                alertDialogBuilder.setPositiveButton(android.R.string.yes,
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                PrivacyManager.setSetting(userId, PrivacyManager.cSettingMethodExpert,
                                        Boolean.toString(true));
                            }
                        });
                alertDialogBuilder.setNegativeButton(android.R.string.no,
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                elvRestriction.collapseGroup(groupPosition);
                            }
                        });
                alertDialogBuilder.setCancelable(false);

                AlertDialog alertDialog = alertDialogBuilder.create();
                alertDialog.show();

            }
        }
    });

    // Go to method
    if (restrictionName != null) {
        int groupPosition = new ArrayList<String>(PrivacyManager.getRestrictions(this).values())
                .indexOf(restrictionName);
        elvRestriction.setSelectedGroup(groupPosition);
        elvRestriction.expandGroup(groupPosition);
        if (methodName != null) {
            Version version = new Version(Util.getSelfVersionName(this));
            int childPosition = PrivacyManager.getHooks(restrictionName, version)
                    .indexOf(new Hook(restrictionName, methodName));
            elvRestriction.setSelectedChild(groupPosition, childPosition, true);
        }
    }

    // Listen for package add/remove
    IntentFilter iff = new IntentFilter();
    iff.addAction(Intent.ACTION_PACKAGE_REMOVED);
    iff.addDataScheme("package");
    registerReceiver(mPackageChangeReceiver, iff);
    mPackageChangeReceiverRegistered = true;

    // Up navigation
    getActionBar().setDisplayHomeAsUpEnabled(true);

    // Tutorial
    if (!PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingTutorialDetails, false)) {
        ((ScrollView) findViewById(R.id.svTutorialHeader)).setVisibility(View.VISIBLE);
        ((ScrollView) findViewById(R.id.svTutorialDetails)).setVisibility(View.VISIBLE);
    }
    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ViewParent parent = view.getParent();
            while (!parent.getClass().equals(ScrollView.class))
                parent = parent.getParent();
            ((View) parent).setVisibility(View.GONE);
            PrivacyManager.setSetting(userId, PrivacyManager.cSettingTutorialDetails, Boolean.TRUE.toString());
        }
    };
    ((Button) findViewById(R.id.btnTutorialHeader)).setOnClickListener(listener);
    ((Button) findViewById(R.id.btnTutorialDetails)).setOnClickListener(listener);

    // Process actions
    if (extras.containsKey(cAction)) {
        NotificationManager notificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        notificationManager.cancel(mAppInfo.getUid());
        if (extras.getInt(cAction) == cActionClear)
            optionClear();
        else if (extras.getInt(cAction) == cActionSettings)
            optionSettings();
    }
}

From source file:com.qihoo.permmgr.PermManager.java

/**
 * ?permmgr.xmlroot??//ww w  . ja v a 2  s  .c om
 */
private void changeUidToMyReal() {
    int i = this.mMyRealUid;
    try {
        if (Process.myUid() == 0) {
            File localFile = new File("/data/data/" + this.mContext.getPackageName() + "/shared_prefs/");
            String[] arrayOfString = new String[3];
            arrayOfString[0] = "chown";
            arrayOfString[1] = (i + "." + i);
            arrayOfString[2] = "permmgr.xml";
            com.qihoo.permmgr.util.b.a(localFile, arrayOfString);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:androidx.media.MediaSession2ImplBase.java

MediaSession2ImplBase(Context context, MediaSessionCompat sessionCompat, String id, MediaPlayerBase player,
        MediaPlaylistAgent playlistAgent, VolumeProviderCompat volumeProvider, PendingIntent sessionActivity,
        Executor callbackExecutor, SessionCallback callback) {
    mContext = context;//from  w w  w. java  2s .  c om
    mHandlerThread = new HandlerThread("MediaController2_Thread");
    mHandlerThread.start();
    mHandler = new Handler(mHandlerThread.getLooper());

    mSessionCompat = sessionCompat;
    mSession2Stub = new MediaSession2StubImplBase(this);
    mSessionCompat.setCallback(mSession2Stub, mHandler);
    mSessionCompat.setSessionActivity(sessionActivity);

    mId = id;
    mCallback = callback;
    mCallbackExecutor = callbackExecutor;
    mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

    // TODO: Set callback values properly
    mPlayerEventCallback = new MyPlayerEventCallback(this);
    mPlaylistEventCallback = new MyPlaylistEventCallback(this);

    // Infer type from the id and package name.
    String libraryService = getServiceName(context, MediaLibraryService2.SERVICE_INTERFACE, id);
    String sessionService = getServiceName(context, MediaSessionService2.SERVICE_INTERFACE, id);
    if (sessionService != null && libraryService != null) {
        throw new IllegalArgumentException(
                "Ambiguous session type. Multiple" + " session services define the same id=" + id);
    } else if (libraryService != null) {
        mSessionToken = new SessionToken2(Process.myUid(), TYPE_LIBRARY_SERVICE, context.getPackageName(),
                libraryService, id, mSessionCompat.getSessionToken());
    } else if (sessionService != null) {
        mSessionToken = new SessionToken2(Process.myUid(), TYPE_SESSION_SERVICE, context.getPackageName(),
                sessionService, id, mSessionCompat.getSessionToken());
    } else {
        mSessionToken = new SessionToken2(Process.myUid(), TYPE_SESSION, context.getPackageName(), null, id,
                mSessionCompat.getSessionToken());
    }
    updatePlayer(player, playlistAgent, volumeProvider);
}

From source file:com.brainasylum.andruid.UniqueIdentifierManager.java

private static boolean canWriteExternalStorage(Context context) {
    return (context.checkPermission("android.permission.WRITE_EXTERNAL_STORAGE", Process.myPid(),
            Process.myUid()) == 0) && (isSdCardMounted());
}