Skip to content

Commit 3aef6ef

Browse files
committed
Better fix for apps that use multiple commands
1 parent a87a7e6 commit 3aef6ef

16 files changed

+267
-138
lines changed

res/layout-land-v14/request_buttons.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,5 @@
3636
android:ellipsize="none"
3737
android:text="@string/allow" />
3838

39-
<CheckBox android:id="@+id/check_remember"
40-
android:layout_width="match_parent"
41-
android:layout_height="wrap_content"
42-
android:layout_weight="1"
43-
android:text="@string/remember" />
44-
4539
</LinearLayout>
4640
</merge>

res/layout-land/activity_request.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,14 @@
4747

4848
<include layout="@layout/request_details" />
4949

50+
<CheckBox android:id="@+id/check_any"
51+
android:layout_width="fill_parent"
52+
android:layout_height="wrap_content"
53+
android:text="@string/any" />
54+
55+
<CheckBox android:id="@+id/check_remember"
56+
android:layout_width="fill_parent"
57+
android:layout_height="wrap_content"
58+
android:text="@string/remember" />
5059
<include layout="@layout/request_buttons" />
5160
</LinearLayout>

res/layout-land/activity_request_pin.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@
5353

5454
<include layout="@layout/request_details" />
5555

56+
<CheckBox android:id="@+id/check_any"
57+
android:layout_width="fill_parent"
58+
android:layout_height="wrap_content"
59+
android:text="@string/any" />
60+
5661
<CheckBox android:id="@+id/check_remember"
5762
android:layout_width="fill_parent"
5863
android:layout_height="wrap_content"

res/layout-land/request_buttons.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,5 @@
3636
android:ellipsize="none"
3737
android:text="@string/deny" />
3838

39-
<CheckBox android:id="@+id/check_remember"
40-
android:layout_width="match_parent"
41-
android:layout_height="wrap_content"
42-
android:layout_weight="1"
43-
android:text="@string/remember" />
44-
4539
</LinearLayout>
4640
</merge>

res/layout-port-v14/request_buttons.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,4 @@
3333
android:text="@string/allow" />
3434

3535
</LinearLayout>
36-
37-
<CheckBox android:id="@+id/check_remember"
38-
android:layout_width="fill_parent"
39-
android:layout_height="wrap_content"
40-
android:text="@string/remember" />
41-
4236
</merge>

res/layout-port/activity_request.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@
4747

4848
<include layout="@layout/request_details" />
4949

50+
<CheckBox android:id="@+id/check_any"
51+
android:layout_width="fill_parent"
52+
android:layout_height="wrap_content"
53+
android:text="@string/any" />
54+
55+
<CheckBox android:id="@+id/check_remember"
56+
android:layout_width="fill_parent"
57+
android:layout_height="wrap_content"
58+
android:text="@string/remember" />
59+
5060
<include layout="@layout/request_buttons" />
5161

5262
</LinearLayout>

res/layout-port/activity_request_pin.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,16 @@
4040

4141
<include layout="@layout/request_details" />
4242

43-
<include layout="@layout/pin_layout" />
44-
43+
<CheckBox android:id="@+id/check_any"
44+
android:layout_width="fill_parent"
45+
android:layout_height="wrap_content"
46+
android:text="@string/any" />
47+
4548
<CheckBox android:id="@+id/check_remember"
4649
android:layout_width="fill_parent"
4750
android:layout_height="wrap_content"
4851
android:text="@string/remember" />
4952

53+
<include layout="@layout/pin_layout" />
54+
5055
</LinearLayout>

res/layout-port/request_buttons.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,4 @@
3434

3535
</LinearLayout>
3636

37-
<CheckBox android:id="@+id/check_remember"
38-
android:layout_width="fill_parent"
39-
android:layout_height="wrap_content"
40-
android:text="@string/remember" />
41-
4237
</merge>

res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<string name="set">Set</string>
5959
<string name="remember">Remember</string>
6060
<string name="remember_disabled">Remembering disabled until su is updated</string>
61+
<string name="any">Apply to any commands from this app</string>
6162
<string name="request">%1$s as %2$s (uid: %3$d)</string>
6263
<string name="unknown">Unknown name</string>
6364

src/com/noshufou/android/su/AppDetailsFragment.java

Lines changed: 65 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
******************************************************************************/
1616
package com.noshufou.android.su;
1717

18+
import java.util.ArrayList;
19+
1820
import android.app.Activity;
1921
import android.content.ContentResolver;
2022
import android.content.ContentUris;
@@ -79,7 +81,11 @@ public class AppDetailsFragment extends SherlockListFragment
7981
private static final int DETAILS_LOADER = 1;
8082
private static final int LOG_LOADER = 2;
8183

84+
private int mShownUid = -1;
85+
private int mShownAllow = 0;
8286
private long mShownIndex = -1;
87+
88+
private ArrayList<Long> mShownIndexes = new ArrayList<Long>();
8389

8490
private boolean mReady = false;
8591
private boolean mDualPane = false;
@@ -124,6 +130,13 @@ public void setShownIndex(long index) {
124130
getLoaderManager().restartLoader(LOG_LOADER, null, this);
125131
}
126132

133+
public void setShownItem(long id, int uid, int allow) {
134+
mShownUid = uid;
135+
mShownAllow = allow;
136+
getLoaderManager().restartLoader(DETAILS_LOADER, null, this);
137+
getLoaderManager().restartLoader(LOG_LOADER, null, this);
138+
}
139+
127140
@Override
128141
public void onCreate(Bundle savedInstanceState) {
129142
super.onCreate(savedInstanceState);
@@ -163,11 +176,14 @@ public void onActivityCreated(Bundle savedInstanceState) {
163176

164177
if (savedInstanceState != null &&
165178
savedInstanceState.containsKey("mShownIndex")) {
166-
mShownIndex = savedInstanceState.getLong("mShownIndex");
179+
mShownUid = savedInstanceState.getInt("mShownUid");
180+
mShownAllow = savedInstanceState.getInt("mShownAllow");
167181
} else if (getArguments() != null) {
168-
mShownIndex = getArguments().getLong("index", 0);
182+
mShownUid = getArguments().getInt("uid", 0);
183+
mShownAllow = getArguments().getInt("allow", 0);
169184
} else {
170-
mShownIndex = 0;
185+
mShownUid = -1;
186+
mShownAllow = 0;
171187
}
172188

173189
setupListView();
@@ -261,8 +277,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
261277

262278
@Override
263279
public void onSaveInstanceState(Bundle outState) {
264-
if (mShownIndex != -1) {
265-
outState.putLong("mShownIndex", mShownIndex);
280+
if (mShownUid != -1) {
281+
outState.putInt("mShownUid", mShownUid);
282+
outState.putInt("mShownAllow", mShownAllow);
266283
}
267284

268285
super.onSaveInstanceState(outState);
@@ -292,7 +309,7 @@ private void setOptions(int option) {
292309
values.put(Apps.LOGGING, mLoggingEnabled);
293310
break;
294311
}
295-
cr.update(ContentUris.withAppendedId(Apps.CONTENT_URI, mShownIndex),
312+
cr.update(ContentUris.withAppendedId(Apps.CONTENT_URI_UID, mShownUid),
296313
values, null, null);
297314
getSherlockActivity().invalidateOptionsMenu();
298315
}
@@ -310,7 +327,6 @@ public void toggle(View view) {
310327
} else {
311328
doToggle();
312329
}
313-
314330
}
315331

316332
@Override
@@ -322,20 +338,23 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
322338

323339
private void doToggle() {
324340
ContentResolver cr = getActivity().getContentResolver();
325-
Uri uri = Uri.withAppendedPath(Apps.CONTENT_URI, String.valueOf(mShownIndex));
326341

327-
ContentValues values = new ContentValues();
328-
values.put(Apps.ALLOW, mAllow == 1?0:1);
329-
cr.update(uri, values, null, null);
330-
331-
// Update the log
332-
values.clear();
333-
values.put(Logs.DATE, System.currentTimeMillis());
334-
values.put(Logs.TYPE, Logs.LogType.TOGGLE);
335-
cr.insert(Uri.withAppendedPath(Logs.CONTENT_URI, String.valueOf(mShownIndex)), values);
336-
Intent intent = new Intent(getActivity(), ResultService.class);
337-
intent.putExtra(ResultService.EXTRA_ACTION, ResultService.ACTION_RECYCLE);
338-
getActivity().startService(intent);
342+
for (Long id : mShownIndexes) {
343+
Uri uri = Uri.withAppendedPath(Apps.CONTENT_URI, String.valueOf(id));
344+
ContentValues values = new ContentValues();
345+
values.put(Apps.ALLOW, mAllow == 1?0:1);
346+
cr.update(uri, values, null, null);
347+
348+
// Update the log
349+
values.clear();
350+
values.put(Logs.DATE, System.currentTimeMillis());
351+
values.put(Logs.TYPE, Logs.LogType.TOGGLE);
352+
cr.insert(Uri.withAppendedPath(Logs.CONTENT_URI, String.valueOf(id)), values);
353+
Intent intent = new Intent(getActivity(), ResultService.class);
354+
intent.putExtra(ResultService.EXTRA_ACTION, ResultService.ACTION_RECYCLE);
355+
getActivity().startService(intent);
356+
}
357+
setShownItem(mShownIndex, mShownUid, mShownAllow == 0?1:0);
339358
}
340359

341360
public void forget(View view) {
@@ -344,9 +363,10 @@ public void forget(View view) {
344363
}
345364

346365
ContentResolver cr = getActivity().getContentResolver();
347-
Uri uri = Uri.withAppendedPath(Apps.CONTENT_URI, String.valueOf(mShownIndex));
348-
349-
cr.delete(uri, null, null);
366+
for (Long id : mShownIndexes) {
367+
Uri uri = Uri.withAppendedPath(Apps.CONTENT_URI, String.valueOf(id));
368+
cr.delete(uri, null, null);
369+
}
350370
closeDetails();
351371
}
352372

@@ -356,8 +376,11 @@ public void clearLog(View view) {
356376

357377
@Override
358378
public void clearLog() {
359-
if (mShownIndex != -1) {
360-
getActivity().getContentResolver().delete(ContentUris.withAppendedId(Logs.CONTENT_URI, mShownIndex), null, null);
379+
if (!mShownIndexes.isEmpty()) {
380+
for (Long id : mShownIndexes) {
381+
getActivity().getContentResolver()
382+
.delete(ContentUris.withAppendedId(Logs.CONTENT_URI, id), null, null);
383+
}
361384
}
362385
}
363386

@@ -380,12 +403,16 @@ public Loader<Cursor> onCreateLoader(int id, Bundle args) {
380403
switch (id) {
381404
case DETAILS_LOADER:
382405
return new CursorLoader(getActivity(),
383-
ContentUris.withAppendedId(Apps.CONTENT_URI, mShownIndex),
384-
DETAILS_PROJECTION, null, null, null);
406+
ContentUris.withAppendedId(Apps.CONTENT_URI_UID, mShownUid),
407+
DETAILS_PROJECTION,
408+
Apps.ALLOW + "=?",
409+
new String[] { String.valueOf(mShownAllow) },
410+
null);
385411
case LOG_LOADER:
386412
return new CursorLoader(getActivity(),
387-
ContentUris.withAppendedId(Logs.CONTENT_URI, mShownIndex),
388-
LogAdapter.PROJECTION, null, null, null);
413+
ContentUris.withAppendedId(Apps.CONTENT_UID_LOGS, mShownUid),
414+
LogAdapter.PROJECTION, Apps.ALLOW + "=?", new String[] { String.valueOf(mShownAllow) },
415+
null);
389416
default:
390417
throw new IllegalArgumentException("Unknown Loader: " + id);
391418
}
@@ -436,6 +463,15 @@ public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
436463
mNotificationsEnabled = notificationsStr.equals("1")?true:false;
437464
mLoggingEnabled = loggingStr.equals("1")?true:false;
438465
}
466+
StringBuilder commandText = new StringBuilder(data.getString(DETAILS_COLUMN_EXEC_CMD));
467+
mShownIndexes.clear();
468+
mShownIndexes.add(data.getLong(0));
469+
while (data.moveToNext()) {
470+
commandText.append(", ");
471+
commandText.append(data.getString(DETAILS_COLUMN_EXEC_CMD));
472+
mShownIndexes.add(data.getLong(0));
473+
}
474+
mCommandText.setText(commandText.toString());
439475
}
440476
mReady = true;
441477
getSherlockActivity().invalidateOptionsMenu();

src/com/noshufou/android/su/AppListFragment.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,12 @@ public void onResume() {
108108

109109
@Override
110110
public void onListItemClick(ListView l, View v, int position, long id) {
111-
((HomeActivity)getActivity()).showDetails(id);
111+
Cursor c = mAdapter.getCursor();
112+
c.moveToPosition(position);
113+
((HomeActivity)getActivity()).showDetails(
114+
c.getLong(COLUMN_ID),
115+
c.getInt(COLUMN_UID),
116+
c.getInt(COLUMN_ALLOW));
112117
}
113118

114119
private void setupListView() {
@@ -135,7 +140,7 @@ private void setupListView() {
135140

136141
@Override
137142
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
138-
return new CursorLoader(getActivity(), Apps.CONTENT_URI, PROJECTION,
143+
return new CursorLoader(getActivity(), Apps.CONTENT_URI_UID_GRP, PROJECTION,
139144
Apps.ALLOW + "!=?", new String[] { String.valueOf(Apps.AllowType.ASK) }, null);
140145
}
141146

src/com/noshufou/android/su/HomeActivity.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,18 @@ public boolean onOptionsItemSelected(MenuItem item) {
160160
return super.onOptionsItemSelected(item);
161161
}
162162

163-
public void showDetails(long id) {
163+
public void showDetails(long id, int uid, int allow) {
164164
if (mDualPane) {
165165
Fragment fragment = getSupportFragmentManager()
166166
.findFragmentById(R.id.fragment_container);
167167
if (fragment instanceof AppDetailsFragment) {
168-
((AppDetailsFragment)fragment).setShownIndex(id);
168+
// ((AppDetailsFragment)fragment).setShownIndex(id);
169+
((AppDetailsFragment)fragment).setShownItem(id, uid, allow);
169170
} else {
170171
Bundle bundle = new Bundle();
171172
bundle.putLong("index", id);
173+
bundle.putInt("uid", uid);
174+
bundle.putInt("allow", allow);
172175
Fragment detailsFragment =
173176
Fragment.instantiate(this, AppDetailsFragment.class.getName(), bundle);
174177
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
@@ -180,6 +183,8 @@ public void showDetails(long id) {
180183
} else {
181184
Intent intent = new Intent(this, AppDetailsActivity.class);
182185
intent.putExtra("index", id);
186+
intent.putExtra("uid", uid);
187+
intent.putExtra("allow", allow);
183188
startActivity(intent);
184189
}
185190
}

0 commit comments

Comments
 (0)