Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Commit

Permalink
Separate global settings for each Android user
Browse files Browse the repository at this point in the history
Closes #1563
  • Loading branch information
M66B committed Mar 16, 2014
1 parent e95c4f0 commit 8700d42
Show file tree
Hide file tree
Showing 12 changed files with 213 additions and 141 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Changelog

* Fixed wrong uid for restricted profiles ([issue](/../../issues/1561))
* Fixed on demand colors by hard coding theme ([issue](/../../issues/1562))
* Separate global settings for each Android user ([issue](/../../issues/1563))
* Updated Slovenian translation

[Open issues](https://github.com/M66B/XPrivacy/issues?state=open)
Expand Down
35 changes: 22 additions & 13 deletions src/biz/bokhorst/xprivacy/ActivityApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.os.Process;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.support.v4.app.NavUtils;
Expand Down Expand Up @@ -113,6 +114,8 @@ public void onReceive(Context context, Intent intent) {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

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

// Check privacy service client
if (!PrivacyService.checkClient())
return;
Expand Down Expand Up @@ -189,7 +192,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

final ImageView imgCbOnDemand = (ImageView) findViewById(R.id.imgCbOnDemand);
if (PrivacyManager.isApplication(mAppInfo.getUid())
&& PrivacyManager.getSettingBool(0, PrivacyManager.cSettingOnDemand, true, false)) {
&& PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingOnDemand, true, false)) {
// Display on-demand state
boolean ondemand = PrivacyManager.getSettingBool(-mAppInfo.getUid(), PrivacyManager.cSettingOnDemand,
false, false);
Expand Down Expand Up @@ -261,7 +264,7 @@ public void onClick(View view) {
getActionBar().setDisplayHomeAsUpEnabled(true);

// Tutorial
if (!PrivacyManager.getSettingBool(0, PrivacyManager.cSettingTutorialDetails, false, false)) {
if (!PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingTutorialDetails, false, false)) {
((ScrollView) findViewById(R.id.svTutorialHeader)).setVisibility(View.VISIBLE);
((ScrollView) findViewById(R.id.svTutorialDetails)).setVisibility(View.VISIBLE);
}
Expand All @@ -272,7 +275,7 @@ public void onClick(View view) {
while (!parent.getClass().equals(ScrollView.class))
parent = parent.getParent();
((View) parent).setVisibility(View.GONE);
PrivacyManager.setSetting(0, PrivacyManager.cSettingTutorialDetails, Boolean.TRUE.toString());
PrivacyManager.setSetting(userId, PrivacyManager.cSettingTutorialDetails, Boolean.TRUE.toString());
}
};
((Button) findViewById(R.id.btnTutorialHeader)).setOnClickListener(listener);
Expand Down Expand Up @@ -484,7 +487,8 @@ private void optionHelp() {
private void optionTutorial() {
((ScrollView) findViewById(R.id.svTutorialHeader)).setVisibility(View.VISIBLE);
((ScrollView) findViewById(R.id.svTutorialDetails)).setVisibility(View.VISIBLE);
PrivacyManager.setSetting(0, PrivacyManager.cSettingTutorialDetails, Boolean.FALSE.toString());
int userId = Util.getUserId(Process.myUid());
PrivacyManager.setSetting(userId, PrivacyManager.cSettingTutorialDetails, Boolean.FALSE.toString());
}

private void optionUsage() {
Expand Down Expand Up @@ -990,8 +994,10 @@ public RestrictionAdapter(int resource, ApplicationInfoEx appInfo, String select
mListRestriction = new ArrayList<String>();
mHook = new LinkedHashMap<Integer, List<Hook>>();

boolean fUsed = PrivacyManager.getSettingBool(0, PrivacyManager.cSettingFUsed, false, false);
boolean fPermission = PrivacyManager.getSettingBool(0, PrivacyManager.cSettingFPermission, false, false);
int userId = Util.getUserId(Process.myUid());
boolean fUsed = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFUsed, false, false);
boolean fPermission = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFPermission, false,
false);

for (String rRestrictionName : PrivacyManager.getRestrictions(ActivityApp.this).values()) {
boolean isUsed = (PrivacyManager.getUsage(mAppInfo.getUid(), rRestrictionName, null) > 0);
Expand Down Expand Up @@ -1064,11 +1070,12 @@ public GroupHolderTask(int thePosition, GroupViewHolder theHolder, String theRes
protected Object doInBackground(Object... params) {
if (restrictionName != null) {
// Get info
int userId = Util.getUserId(Process.myUid());
used = (PrivacyManager.getUsage(mAppInfo.getUid(), restrictionName, null) != 0);
permission = PrivacyManager.hasPermission(ActivityApp.this, mAppInfo, restrictionName);
rstate = new RState(mAppInfo.getUid(), restrictionName, null);
ondemand = (PrivacyManager.isApplication(mAppInfo.getUid()) && PrivacyManager.getSettingBool(0,
PrivacyManager.cSettingOnDemand, true, false));
ondemand = (PrivacyManager.isApplication(mAppInfo.getUid()) && PrivacyManager.getSettingBool(
userId, PrivacyManager.cSettingOnDemand, true, false));
if (ondemand)
ondemand = PrivacyManager.getSettingBool(-mAppInfo.getUid(), PrivacyManager.cSettingOnDemand,
false, false);
Expand Down Expand Up @@ -1225,9 +1232,10 @@ public void onClick(View view) {

private List<Hook> getHooks(int groupPosition) {
if (!mHook.containsKey(groupPosition)) {
boolean fUsed = PrivacyManager.getSettingBool(0, PrivacyManager.cSettingFUsed, false, false);
boolean fPermission = PrivacyManager
.getSettingBool(0, PrivacyManager.cSettingFPermission, false, false);
int userId = Util.getUserId(Process.myUid());
boolean fUsed = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFUsed, false, false);
boolean fPermission = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFPermission, false,
false);
List<Hook> listMethod = new ArrayList<Hook>();
String restrictionName = mListRestriction.get(groupPosition);
for (Hook md : PrivacyManager.getHooks((String) getGroup(groupPosition))) {
Expand Down Expand Up @@ -1313,13 +1321,14 @@ public ChildHolderTask(int gPosition, int cPosition, ChildViewHolder theHolder,
protected Object doInBackground(Object... params) {
if (restrictionName != null) {
// Get info
int userId = Util.getUserId(Process.myUid());
md = (Hook) getChild(groupPosition, childPosition);
lastUsage = PrivacyManager.getUsage(mAppInfo.getUid(), restrictionName, md.getName());
parent = PrivacyManager.getRestrictionEx(mAppInfo.getUid(), restrictionName, null);
permission = PrivacyManager.hasPermission(ActivityApp.this, mAppInfo, md);
rstate = new RState(mAppInfo.getUid(), restrictionName, md.getName());
ondemand = (PrivacyManager.isApplication(mAppInfo.getUid()) && PrivacyManager.getSettingBool(0,
PrivacyManager.cSettingOnDemand, true, false));
ondemand = (PrivacyManager.isApplication(mAppInfo.getUid()) && PrivacyManager.getSettingBool(
userId, PrivacyManager.cSettingOnDemand, true, false));
if (ondemand)
ondemand = PrivacyManager.getSettingBool(-mAppInfo.getUid(), PrivacyManager.cSettingOnDemand,
false, false);
Expand Down
4 changes: 3 additions & 1 deletion src/biz/bokhorst/xprivacy/ActivityBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.graphics.PorterDuff.Mode;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Process;
import android.util.TypedValue;
import android.view.View;
import android.widget.TextView;
Expand All @@ -26,7 +27,8 @@ protected void onCreate(Bundle savedInstanceState) {

if (PrivacyService.checkClient()) {
// Set theme
String themeName = PrivacyManager.getSetting(0, PrivacyManager.cSettingTheme, "", false);
int userId = Util.getUserId(Process.myUid());
String themeName = PrivacyManager.getSetting(userId, PrivacyManager.cSettingTheme, "", false);
mThemeId = (themeName.equals("Dark") ? R.style.CustomTheme : R.style.CustomTheme_Light);
setTheme(mThemeId);
} else {
Expand Down
Loading

4 comments on commit 8700d42

@jpeg729
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concerning dangerous functions. Only the primary user can set them, and I don't understand why. Why not let the secondary user set his own dangerous functions.

If I read this right, given that userId is given wherever cDangerousSetting is checked, the secondary users are stuck with the developer's defaults for dangerous functions.

@M66B
Copy link
Owner

@M66B M66B commented on 8700d42 Mar 17, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jpeg729
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't hook.toggleDangerous run in the app process?
In which case, why is getting the userId a problem?

@M66B
Copy link
Owner

@M66B M66B commented on 8700d42 Mar 17, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'toggle' is not the problem, but 'is' is. This could be solved by passing the uid.

Please sign in to comment.