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

Commit

Permalink
On demand restricting control in application list
Browse files Browse the repository at this point in the history
Fixes #1615
  • Loading branch information
M66B committed Apr 8, 2014
1 parent a7dbeed commit 9ad3f7e
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Changelog
**Next release**

* No allow/deny once for functions that require a restart ([issue](/../../issues/1622))
* On demand restricting control in application list ([issue](/../../issues/1615))
* Updated Polish translation
* Updated Slovak translation

Expand Down
25 changes: 13 additions & 12 deletions res/layout/mainentry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@

<LinearLayout
android:id="@+id/llName"
android:layout_width="match_parent"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="@drawable/list_item_pressed"
android:clickable="true"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
Expand All @@ -86,7 +87,8 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceSmall" />
android:textAppearance="?android:attr/textAppearanceSmall"
tools:ignore="NestedWeights" />

<ImageView
android:id="@+id/imgCbRestricted"
Expand All @@ -107,17 +109,16 @@
android:layout_marginLeft="3dip"
android:layout_marginRight="3dip"
android:visibility="gone" />

<TextView
android:id="@+id/tvOnDemand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/msg_question"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="bold"
android:visibility="invisible" />
</LinearLayout>

<ImageView
android:id="@+id/imgCbAsk"
android:layout_width="32dip"
android:layout_height="32dip"
android:layout_gravity="center_vertical"
android:contentDescription="@string/title_restrict"
android:paddingLeft="3dip"
android:visibility="invisible" />
</LinearLayout>

</LinearLayout>
61 changes: 47 additions & 14 deletions src/biz/bokhorst/xprivacy/ActivityMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -1563,8 +1563,8 @@ private class ViewHolder {
public TextView tvName;
public ImageView imgCbRestricted;
public ProgressBar pbRunning;
public TextView tvOnDemand;
public LinearLayout llName;
public ImageView imgCbAsk;

public ViewHolder(View theRow, int thePosition) {
row = theRow;
Expand All @@ -1579,8 +1579,8 @@ public ViewHolder(View theRow, int thePosition) {
tvName = (TextView) row.findViewById(R.id.tvName);
imgCbRestricted = (ImageView) row.findViewById(R.id.imgCbRestricted);
pbRunning = (ProgressBar) row.findViewById(R.id.pbRunning);
tvOnDemand = (TextView) row.findViewById(R.id.tvOnDemand);
llName = (LinearLayout) row.findViewById(R.id.llName);
imgCbAsk = (ImageView) row.findViewById(R.id.imgCbAsk);
}
}

Expand All @@ -1593,6 +1593,7 @@ private class HolderTask extends AsyncTask<Object, Object, Object> {
private boolean enabled;
private boolean granted;
private RState rstate;
private boolean gondemand;
private boolean ondemand;

public HolderTask(int thePosition, ViewHolder theHolder, ApplicationInfoEx theAppInfo) {
Expand All @@ -1617,7 +1618,10 @@ protected Object doInBackground(Object... params) {
false);

// Get if on demand
ondemand = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingOnDemand, true, false);
gondemand = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingOnDemand, true, false);
ondemand = (PrivacyManager.isApplication(xAppInfo.getUid()) && (mRestrictionName == null ? true
: PrivacyManager.getSettingBool(-xAppInfo.getUid(), PrivacyManager.cSettingOnDemand, false,
false)));

// Get if granted
granted = true;
Expand Down Expand Up @@ -1658,10 +1662,14 @@ else if (state == STATE_SHARED)
holder.imgIcon.setVisibility(View.VISIBLE);

// Display on demand
if (ondemand)
holder.tvOnDemand.setVisibility(rstate.asked ? View.INVISIBLE : View.VISIBLE);
else
holder.tvOnDemand.setVisibility(View.GONE);
if (gondemand) {
if (ondemand) {
holder.imgCbAsk.setImageBitmap(getAskBoxImage(rstate));
holder.imgCbAsk.setVisibility(View.VISIBLE);
} else
holder.imgCbAsk.setVisibility(View.INVISIBLE);
} else
holder.imgCbAsk.setVisibility(View.GONE);

// Display usage
holder.tvName.setTypeface(null, used ? Typeface.BOLD_ITALIC : Typeface.NORMAL);
Expand Down Expand Up @@ -1752,6 +1760,35 @@ public void onClick(DialogInterface dialog, int which) {
}
}
});

// Listen for ask changes
if (gondemand && ondemand)
holder.imgCbAsk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
holder.imgCbAsk.setVisibility(View.GONE);
holder.pbRunning.setVisibility(View.VISIBLE);

new AsyncTask<Object, Object, Object>() {
@Override
protected Object doInBackground(Object... arg0) {
rstate.toggleAsked();
return null;
}

@Override
protected void onPostExecute(Object result) {
// Needed to update children
notifyDataSetChanged();

holder.pbRunning.setVisibility(View.GONE);
holder.imgCbAsk.setVisibility(View.VISIBLE);
}
}.executeOnExecutor(mExecutor);
}
});
else
holder.imgCbAsk.setClickable(false);
}
}

Expand Down Expand Up @@ -1782,8 +1819,7 @@ protected void onPostExecute(Object result) {
// Update stored state
rstate = new RState(xAppInfo.getUid(), mRestrictionName, null);
holder.imgCbRestricted.setImageBitmap(getCheckBoxImage(rstate));
if (ondemand)
holder.tvOnDemand.setVisibility(rstate.asked ? View.INVISIBLE : View.VISIBLE);
holder.imgCbAsk.setImageBitmap(getAskBoxImage(rstate));

// Notify restart
if (oldState.contains(true))
Expand Down Expand Up @@ -1823,10 +1859,7 @@ protected void onPostExecute(Object result) {
// Update restriction display
rstate = new RState(xAppInfo.getUid(), mRestrictionName, null);
holder.imgCbRestricted.setImageBitmap(getCheckBoxImage(rstate));

// Update on demand
if (ondemand)
holder.tvOnDemand.setVisibility(rstate.asked ? View.INVISIBLE : View.VISIBLE);
holder.imgCbAsk.setImageBitmap(getAskBoxImage(rstate));

// Notify restart
if (!newState.equals(oldState))
Expand Down Expand Up @@ -1893,7 +1926,7 @@ public void onClick(View view) {
holder.imgInternet.setVisibility(View.INVISIBLE);
holder.imgFrozen.setVisibility(View.INVISIBLE);
holder.imgCbRestricted.setVisibility(View.INVISIBLE);
holder.tvOnDemand.setVisibility(View.INVISIBLE);
holder.imgCbAsk.setVisibility(View.INVISIBLE);
holder.tvName.setEnabled(false);
holder.imgCbRestricted.setEnabled(false);
holder.llName.setEnabled(false);
Expand Down
23 changes: 14 additions & 9 deletions src/biz/bokhorst/xprivacy/RState.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ public RState(int uid, String restrictionName, String methodName) {
if (methodName == null) {
if (restrictionName == null) {
// Examine the category state
asked = true;
for (String rRestrictionName : PrivacyManager.getRestrictions()) {
PRestriction query = PrivacyManager.getRestrictionEx(uid, rRestrictionName, null);
allRestricted = (allRestricted && query.restricted);
someRestricted = (someRestricted || query.restricted);
if (!query.asked)
asked = false;
allAsk = (allAsk && !query.asked);
someAsk = (someAsk || !query.asked);
}
asked = !someAsk;
} else {
// Examine the category/method states
PRestriction query = PrivacyManager.getRestrictionEx(uid, restrictionName, null);
Expand Down Expand Up @@ -97,11 +97,16 @@ public void toggleRestriction() {

public void toggleAsked() {
asked = !asked;
// Avoid re-doing all exceptions for dangerous functions
List<PRestriction> listPRestriction = new ArrayList<PRestriction>();
listPRestriction.add(new PRestriction(mUid, mRestrictionName, mMethodName, restricted, asked));
PrivacyManager.setRestrictionList(listPRestriction);
PrivacyManager.setSetting(mUid, PrivacyManager.cSettingState, Integer.toString(ActivityMain.STATE_CHANGED));
PrivacyManager.setSetting(mUid, PrivacyManager.cSettingModifyTime, Long.toString(System.currentTimeMillis()));
if (mRestrictionName == null)
PrivacyManager.setSetting(mUid, PrivacyManager.cSettingOnDemand, Boolean.toString(!asked));
else {
// Avoid re-doing all exceptions for dangerous functions
List<PRestriction> listPRestriction = new ArrayList<PRestriction>();
listPRestriction.add(new PRestriction(mUid, mRestrictionName, mMethodName, restricted, asked));
PrivacyManager.setRestrictionList(listPRestriction);
PrivacyManager.setSetting(mUid, PrivacyManager.cSettingState, Integer.toString(ActivityMain.STATE_CHANGED));
PrivacyManager.setSetting(mUid, PrivacyManager.cSettingModifyTime,
Long.toString(System.currentTimeMillis()));
}
}
}

0 comments on commit 9ad3f7e

Please sign in to comment.