List of usage examples for android.os Process myUid
public static final int myUid()
From source file:biz.bokhorst.xprivacy.ActivityMain.java
private void selectRestriction(int pos) { if (mAppAdapter != null) { int userId = Util.getUserId(Process.myUid()); String restrictionName = (pos == 0 ? null : (String) PrivacyManager.getRestrictions(this).values().toArray()[pos - 1]); mAppAdapter.setRestrictionName(restrictionName); PrivacyManager.setSetting(userId, PrivacyManager.cSettingSelectedCategory, restrictionName); applyFilter();//from ww w.j a v a2 s . c o m } }
From source file:biz.bokhorst.xprivacy.Util.java
public static String sha1(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException { // SHA1//from w w w .j a va 2s . co m int userId = Util.getUserId(Process.myUid()); String salt = PrivacyManager.getSalt(userId); MessageDigest digest = MessageDigest.getInstance("SHA-1"); byte[] bytes = (text + salt).getBytes("UTF-8"); digest.update(bytes, 0, bytes.length); bytes = digest.digest(); StringBuilder sb = new StringBuilder(); for (byte b : bytes) sb.append(String.format("%02X", b)); return sb.toString(); }
From source file:biz.bokhorst.xprivacy.ActivityMain.java
private void applyFilter() { if (mAppAdapter != null) { ProgressBar pbFilter = (ProgressBar) findViewById(R.id.pbFilter); TextView tvStats = (TextView) findViewById(R.id.tvStats); TextView tvState = (TextView) findViewById(R.id.tvState); // Get settings int userId = Util.getUserId(Process.myUid()); boolean fUsed = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFUsed, false); boolean fInternet = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFInternet, false); boolean fRestriction = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFRestriction, false);/*from w w w. jav a 2s .co m*/ boolean fRestrictionNot = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFRestrictionNot, false); boolean fPermission = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFPermission, true); boolean fOnDemand = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFOnDemand, false); boolean fOnDemandNot = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFOnDemandNot, false); boolean fUser = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFUser, true); boolean fSystem = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFSystem, false); String filter = String.format("%s\n%b\n%b\n%b\n%b\n%b\n%b\n%b\n%b\n%b", searchQuery, fUsed, fInternet, fRestriction, fRestrictionNot, fPermission, fOnDemand, fOnDemandNot, fUser, fSystem); pbFilter.setVisibility(ProgressBar.VISIBLE); tvStats.setVisibility(TextView.GONE); // Adjust progress state width RelativeLayout.LayoutParams tvStateLayout = (RelativeLayout.LayoutParams) tvState.getLayoutParams(); tvStateLayout.addRule(RelativeLayout.LEFT_OF, R.id.pbFilter); mAppAdapter.getFilter().filter(filter); } }
From source file:biz.bokhorst.xprivacy.Util.java
public static String md5(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException { // MD5/* w w w . j a v a 2 s . c o m*/ int userId = Util.getUserId(Process.myUid()); String salt = PrivacyManager.getSalt(userId); byte[] bytes = MessageDigest.getInstance("MD5").digest((text + salt).getBytes("UTF-8")); StringBuilder sb = new StringBuilder(); for (byte b : bytes) sb.append(String.format("%02X", b)); return sb.toString(); }
From source file:net.sf.xfd.provider.PublicProvider.java
@Override public Uri canonicalize(@NonNull Uri uri) { try {// w w w . j a v a 2 s . com base.assertAbsolute(uri); String grantMode = uri.getQueryParameter(URI_ARG_MODE); if (TextUtils.isEmpty(grantMode)) { grantMode = "r"; } verifyMac(uri, grantMode, grantMode); final int flags = ParcelFileDescriptor.parseMode(grantMode); final Context context = getContext(); assert context != null; final String packageName = context.getPackageName(); final Uri canon = DocumentsContract.buildDocumentUri(packageName + FileProvider.AUTHORITY_SUFFIX, canonString(uri.getPath())); final int callerUid = Binder.getCallingUid(); if (callerUid != Process.myUid()) { int grantFlags = Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION; if ((flags & ParcelFileDescriptor.MODE_READ_ONLY) == flags) { grantFlags |= Intent.FLAG_GRANT_READ_URI_PERMISSION; } else if ((flags & ParcelFileDescriptor.MODE_WRITE_ONLY) == flags) grantFlags |= Intent.FLAG_GRANT_WRITE_URI_PERMISSION; else { grantFlags |= Intent.FLAG_GRANT_WRITE_URI_PERMISSION; grantFlags |= Intent.FLAG_GRANT_READ_URI_PERMISSION; } final String[] packages; final String caller = getCallingPackage(); if (caller != null) { packages = new String[] { caller }; } else { final PackageManager pm = context.getPackageManager(); packages = pm.getPackagesForUid(callerUid); } if (packages != null) { for (String pkg : packages) { context.grantUriPermission(pkg, canon, grantFlags); } } } return canon; } catch (FileNotFoundException e) { return null; } }
From source file:biz.bokhorst.xprivacy.ActivityMain.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { int userId = Util.getUserId(Process.myUid()); boolean mounted = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); boolean updates = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingUpdates, false); menu.findItem(R.id.menu_export).setEnabled(mounted); menu.findItem(R.id.menu_import).setEnabled(mounted); menu.findItem(R.id.menu_submit).setEnabled(Util.hasValidFingerPrint(this)); menu.findItem(R.id.menu_pro).setVisible(!Util.isProEnabled() && Util.hasProLicense(this) == null); menu.findItem(R.id.menu_dump).setVisible(Util.isDebuggable(this)); menu.findItem(R.id.menu_update).setVisible(updates); menu.findItem(R.id.menu_update).setEnabled(mounted); // Update filter count // Get settings boolean fUsed = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFUsed, false); boolean fInternet = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFInternet, false); boolean fRestriction = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFRestriction, false); boolean fPermission = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFPermission, true); boolean fOnDemand = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFOnDemand, false); boolean fUser = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFUser, true); boolean fSystem = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFSystem, false); // Count number of active filters int numberOfFilters = 0; if (fUsed)/* w w w . j a v a2s. co m*/ numberOfFilters++; if (fInternet) numberOfFilters++; if (fRestriction) numberOfFilters++; if (fPermission) numberOfFilters++; if (fOnDemand) numberOfFilters++; if (fUser) numberOfFilters++; if (fSystem) numberOfFilters++; if (numberOfFilters > 0) { Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon_filter) .copy(Bitmap.Config.ARGB_8888, true); Paint paint = new Paint(); paint.setStyle(Style.FILL); paint.setColor(Color.GRAY); paint.setTextSize(bitmap.getWidth() / 3); paint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); String text = Integer.toString(numberOfFilters); Canvas canvas = new Canvas(bitmap); canvas.drawText(text, bitmap.getWidth() - paint.measureText(text), bitmap.getHeight(), paint); MenuItem fMenu = menu.findItem(R.id.menu_filter); fMenu.setIcon(new BitmapDrawable(getResources(), bitmap)); } return super.onPrepareOptionsMenu(menu); }
From source file:biz.bokhorst.xprivacy.ActivityApp.java
private void optionTutorial() { ((ScrollView) findViewById(R.id.svTutorialHeader)).setVisibility(View.VISIBLE); ((ScrollView) findViewById(R.id.svTutorialDetails)).setVisibility(View.VISIBLE); int userId = Util.getUserId(Process.myUid()); PrivacyManager.setSetting(userId, PrivacyManager.cSettingTutorialDetails, Boolean.FALSE.toString()); }
From source file:biz.bokhorst.xprivacy.ActivityMain.java
@SuppressLint("InflateParams") private void optionSort() { LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.sort, null); final RadioGroup rgSMode = (RadioGroup) view.findViewById(R.id.rgSMode); final CheckBox cbSInvert = (CheckBox) view.findViewById(R.id.cbSInvert); // Initialise controls switch (mSortMode) { case SORT_BY_NAME: rgSMode.check(R.id.rbSName);//from w w w . j a v a2 s.c o m break; case SORT_BY_UID: rgSMode.check(R.id.rbSUid); break; case SORT_BY_INSTALL_TIME: rgSMode.check(R.id.rbSInstalled); break; case SORT_BY_UPDATE_TIME: rgSMode.check(R.id.rbSUpdated); break; case SORT_BY_MODIFY_TIME: rgSMode.check(R.id.rbSModified); break; case SORT_BY_STATE: rgSMode.check(R.id.rbSState); break; } cbSInvert.setChecked(mSortInvert); // Build dialog AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityMain.this); alertDialogBuilder.setTitle(R.string.menu_sort); alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher)); alertDialogBuilder.setView(view); alertDialogBuilder.setPositiveButton(ActivityMain.this.getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (rgSMode.getCheckedRadioButtonId()) { case R.id.rbSName: mSortMode = SORT_BY_NAME; break; case R.id.rbSUid: mSortMode = SORT_BY_UID; break; case R.id.rbSInstalled: mSortMode = SORT_BY_INSTALL_TIME; break; case R.id.rbSUpdated: mSortMode = SORT_BY_UPDATE_TIME; break; case R.id.rbSModified: mSortMode = SORT_BY_MODIFY_TIME; break; case R.id.rbSState: mSortMode = SORT_BY_STATE; break; } mSortInvert = cbSInvert.isChecked(); int userId = Util.getUserId(Process.myUid()); PrivacyManager.setSetting(userId, PrivacyManager.cSettingSortMode, Integer.toString(mSortMode)); PrivacyManager.setSetting(userId, PrivacyManager.cSettingSortInverted, Boolean.toString(mSortInvert)); applySort(); } }); alertDialogBuilder.setNegativeButton(ActivityMain.this.getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Do nothing } }); // Show dialog AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); }
From source file:biz.bokhorst.xprivacy.ActivityMain.java
@SuppressLint("InflateParams") private void optionFilter() { LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.filters, null); final CheckBox cbFUsed = (CheckBox) view.findViewById(R.id.cbFUsed); final CheckBox cbFInternet = (CheckBox) view.findViewById(R.id.cbFInternet); final CheckBox cbFPermission = (CheckBox) view.findViewById(R.id.cbFPermission); final CheckBox cbFRestriction = (CheckBox) view.findViewById(R.id.cbFRestriction); final CheckBox cbFRestrictionNot = (CheckBox) view.findViewById(R.id.cbFRestrictionNot); final CheckBox cbFOnDemand = (CheckBox) view.findViewById(R.id.cbFOnDemand); final CheckBox cbFOnDemandNot = (CheckBox) view.findViewById(R.id.cbFOnDemandNot); final CheckBox cbFUser = (CheckBox) view.findViewById(R.id.cbFUser); final CheckBox cbFSystem = (CheckBox) view.findViewById(R.id.cbFSystem); final Button btnDefault = (Button) view.findViewById(R.id.btnDefault); // Get settings final int userId = Util.getUserId(Process.myUid()); boolean fUsed = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFUsed, false); boolean fInternet = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFInternet, false); boolean fPermission = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFPermission, true); boolean fRestriction = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFRestriction, false); boolean fRestrictionNot = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFRestrictionNot, false);/*from w w w.j av a 2 s.co m*/ boolean fOnDemand = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFOnDemand, false); boolean fOnDemandNot = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFOnDemandNot, false); boolean fUser = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFUser, true); boolean fSystem = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFSystem, false); boolean ondemand = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingOnDemand, true); // Setup checkboxes cbFUsed.setChecked(fUsed); cbFInternet.setChecked(fInternet); cbFPermission.setChecked(fPermission); cbFRestriction.setChecked(fRestriction); cbFRestrictionNot.setChecked(fRestrictionNot); cbFOnDemand.setChecked(fOnDemand && ondemand); cbFOnDemandNot.setChecked(fOnDemandNot && ondemand); cbFUser.setChecked(fUser); cbFSystem.setChecked(fSystem); cbFRestrictionNot.setEnabled(fRestriction); cbFOnDemand.setEnabled(ondemand); cbFOnDemandNot.setEnabled(fOnDemand && ondemand); // Manage user/system filter exclusivity OnCheckedChangeListener checkListener = new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (buttonView == cbFUser) { if (isChecked) cbFSystem.setChecked(false); } else if (buttonView == cbFSystem) { if (isChecked) cbFUser.setChecked(false); } else if (buttonView == cbFRestriction) cbFRestrictionNot.setEnabled(cbFRestriction.isChecked()); else if (buttonView == cbFOnDemand) cbFOnDemandNot.setEnabled(cbFOnDemand.isChecked()); } }; cbFUser.setOnCheckedChangeListener(checkListener); cbFSystem.setOnCheckedChangeListener(checkListener); cbFRestriction.setOnCheckedChangeListener(checkListener); cbFOnDemand.setOnCheckedChangeListener(checkListener); // Clear button btnDefault.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { cbFUsed.setChecked(false); cbFInternet.setChecked(false); cbFPermission.setChecked(true); cbFRestriction.setChecked(false); cbFRestrictionNot.setChecked(false); cbFOnDemand.setChecked(false); cbFOnDemandNot.setChecked(false); cbFUser.setChecked(true); cbFSystem.setChecked(false); } }); // Build dialog AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityMain.this); alertDialogBuilder.setTitle(R.string.menu_filter); alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher)); alertDialogBuilder.setView(view); alertDialogBuilder.setPositiveButton(ActivityMain.this.getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { PrivacyManager.setSetting(userId, PrivacyManager.cSettingFUsed, Boolean.toString(cbFUsed.isChecked())); PrivacyManager.setSetting(userId, PrivacyManager.cSettingFInternet, Boolean.toString(cbFInternet.isChecked())); PrivacyManager.setSetting(userId, PrivacyManager.cSettingFRestriction, Boolean.toString(cbFRestriction.isChecked())); PrivacyManager.setSetting(userId, PrivacyManager.cSettingFRestrictionNot, Boolean.toString(cbFRestrictionNot.isChecked())); PrivacyManager.setSetting(userId, PrivacyManager.cSettingFPermission, Boolean.toString(cbFPermission.isChecked())); PrivacyManager.setSetting(userId, PrivacyManager.cSettingFOnDemand, Boolean.toString(cbFOnDemand.isChecked())); PrivacyManager.setSetting(userId, PrivacyManager.cSettingFOnDemandNot, Boolean.toString(cbFOnDemandNot.isChecked())); PrivacyManager.setSetting(userId, PrivacyManager.cSettingFUser, Boolean.toString(cbFUser.isChecked())); PrivacyManager.setSetting(userId, PrivacyManager.cSettingFSystem, Boolean.toString(cbFSystem.isChecked())); invalidateOptionsMenu(); applyFilter(); } }); alertDialogBuilder.setNegativeButton(ActivityMain.this.getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); // Show dialog AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); }
From source file:biz.bokhorst.xprivacy.ActivityMain.java
@SuppressLint("InflateParams") private void optionTemplate() { final int userId = Util.getUserId(Process.myUid()); // Build view LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.template, null); final Spinner spTemplate = (Spinner) view.findViewById(R.id.spTemplate); Button btnRename = (Button) view.findViewById(R.id.btnRename); ExpandableListView elvTemplate = (ExpandableListView) view.findViewById(R.id.elvTemplate); // Template selector final SpinnerAdapter spAdapter = new SpinnerAdapter(this, android.R.layout.simple_spinner_item); spAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); String defaultName = PrivacyManager.getSetting(userId, Meta.cTypeTemplateName, "0", getString(R.string.title_default)); spAdapter.add(defaultName);//from w w w. ja v a 2s . c o m for (int i = 1; i <= 4; i++) { String alternateName = PrivacyManager.getSetting(userId, Meta.cTypeTemplateName, Integer.toString(i), getString(R.string.title_alternate) + " " + i); spAdapter.add(alternateName); } spTemplate.setAdapter(spAdapter); // Template definition final TemplateListAdapter templateAdapter = new TemplateListAdapter(this, view, R.layout.templateentry); elvTemplate.setAdapter(templateAdapter); elvTemplate.setGroupIndicator(null); spTemplate.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { templateAdapter.notifyDataSetChanged(); } @Override public void onNothingSelected(AdapterView<?> arg0) { templateAdapter.notifyDataSetChanged(); } }); btnRename.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (Util.hasProLicense(ActivityMain.this) == null) { // Redirect to pro page Util.viewUri(ActivityMain.this, cProUri); return; } final int templateId = spTemplate.getSelectedItemPosition(); if (templateId == AdapterView.INVALID_POSITION) return; AlertDialog.Builder dlgRename = new AlertDialog.Builder(spTemplate.getContext()); dlgRename.setTitle(R.string.title_rename); final String original = (templateId == 0 ? getString(R.string.title_default) : getString(R.string.title_alternate) + " " + templateId); dlgRename.setMessage(original); final EditText input = new EditText(spTemplate.getContext()); dlgRename.setView(input); dlgRename.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String name = input.getText().toString(); if (TextUtils.isEmpty(name)) { PrivacyManager.setSetting(userId, Meta.cTypeTemplateName, Integer.toString(templateId), null); name = original; } else { PrivacyManager.setSetting(userId, Meta.cTypeTemplateName, Integer.toString(templateId), name); } spAdapter.remove(spAdapter.getItem(templateId)); spAdapter.insert(name, templateId); spAdapter.notifyDataSetChanged(); } }); dlgRename.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing } }); dlgRename.create().show(); } }); // Build dialog AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); alertDialogBuilder.setTitle(R.string.menu_template); alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher)); alertDialogBuilder.setView(view); alertDialogBuilder.setPositiveButton(getString(R.string.msg_done), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Do nothing } }); // Show dialog AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); }