Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Better fix for apps that use multiple commands
  • Loading branch information
ChainsDD committed Nov 20, 2012
1 parent a87a7e6 commit 3aef6ef
Show file tree
Hide file tree
Showing 16 changed files with 267 additions and 138 deletions.
6 changes: 0 additions & 6 deletions res/layout-land-v14/request_buttons.xml
Expand Up @@ -36,11 +36,5 @@
android:ellipsize="none"
android:text="@string/allow" />

<CheckBox android:id="@+id/check_remember"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/remember" />

</LinearLayout>
</merge>
9 changes: 9 additions & 0 deletions res/layout-land/activity_request.xml
Expand Up @@ -47,5 +47,14 @@

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

<CheckBox android:id="@+id/check_any"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/any" />

<CheckBox android:id="@+id/check_remember"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/remember" />
<include layout="@layout/request_buttons" />
</LinearLayout>
5 changes: 5 additions & 0 deletions res/layout-land/activity_request_pin.xml
Expand Up @@ -53,6 +53,11 @@

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

<CheckBox android:id="@+id/check_any"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/any" />

<CheckBox android:id="@+id/check_remember"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
Expand Down
6 changes: 0 additions & 6 deletions res/layout-land/request_buttons.xml
Expand Up @@ -36,11 +36,5 @@
android:ellipsize="none"
android:text="@string/deny" />

<CheckBox android:id="@+id/check_remember"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/remember" />

</LinearLayout>
</merge>
6 changes: 0 additions & 6 deletions res/layout-port-v14/request_buttons.xml
Expand Up @@ -33,10 +33,4 @@
android:text="@string/allow" />

</LinearLayout>

<CheckBox android:id="@+id/check_remember"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/remember" />

</merge>
10 changes: 10 additions & 0 deletions res/layout-port/activity_request.xml
Expand Up @@ -47,6 +47,16 @@

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

<CheckBox android:id="@+id/check_any"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/any" />

<CheckBox android:id="@+id/check_remember"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/remember" />

<include layout="@layout/request_buttons" />

</LinearLayout>
9 changes: 7 additions & 2 deletions res/layout-port/activity_request_pin.xml
Expand Up @@ -40,11 +40,16 @@

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

<include layout="@layout/pin_layout" />

<CheckBox android:id="@+id/check_any"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/any" />

<CheckBox android:id="@+id/check_remember"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/remember" />

<include layout="@layout/pin_layout" />

</LinearLayout>
5 changes: 0 additions & 5 deletions res/layout-port/request_buttons.xml
Expand Up @@ -34,9 +34,4 @@

</LinearLayout>

<CheckBox android:id="@+id/check_remember"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/remember" />

</merge>
1 change: 1 addition & 0 deletions res/values/strings.xml
Expand Up @@ -58,6 +58,7 @@
<string name="set">Set</string>
<string name="remember">Remember</string>
<string name="remember_disabled">Remembering disabled until su is updated</string>
<string name="any">Apply to any commands from this app</string>
<string name="request">%1$s as %2$s (uid: %3$d)</string>
<string name="unknown">Unknown name</string>

Expand Down
94 changes: 65 additions & 29 deletions src/com/noshufou/android/su/AppDetailsFragment.java
Expand Up @@ -15,6 +15,8 @@
******************************************************************************/
package com.noshufou.android.su;

import java.util.ArrayList;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.ContentUris;
Expand Down Expand Up @@ -79,7 +81,11 @@ public class AppDetailsFragment extends SherlockListFragment
private static final int DETAILS_LOADER = 1;
private static final int LOG_LOADER = 2;

private int mShownUid = -1;
private int mShownAllow = 0;
private long mShownIndex = -1;

private ArrayList<Long> mShownIndexes = new ArrayList<Long>();

private boolean mReady = false;
private boolean mDualPane = false;
Expand Down Expand Up @@ -124,6 +130,13 @@ public void setShownIndex(long index) {
getLoaderManager().restartLoader(LOG_LOADER, null, this);
}

public void setShownItem(long id, int uid, int allow) {
mShownUid = uid;
mShownAllow = allow;
getLoaderManager().restartLoader(DETAILS_LOADER, null, this);
getLoaderManager().restartLoader(LOG_LOADER, null, this);
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -163,11 +176,14 @@ public void onActivityCreated(Bundle savedInstanceState) {

if (savedInstanceState != null &&
savedInstanceState.containsKey("mShownIndex")) {
mShownIndex = savedInstanceState.getLong("mShownIndex");
mShownUid = savedInstanceState.getInt("mShownUid");
mShownAllow = savedInstanceState.getInt("mShownAllow");
} else if (getArguments() != null) {
mShownIndex = getArguments().getLong("index", 0);
mShownUid = getArguments().getInt("uid", 0);
mShownAllow = getArguments().getInt("allow", 0);
} else {
mShownIndex = 0;
mShownUid = -1;
mShownAllow = 0;
}

setupListView();
Expand Down Expand Up @@ -261,8 +277,9 @@ public boolean onOptionsItemSelected(MenuItem item) {

@Override
public void onSaveInstanceState(Bundle outState) {
if (mShownIndex != -1) {
outState.putLong("mShownIndex", mShownIndex);
if (mShownUid != -1) {
outState.putInt("mShownUid", mShownUid);
outState.putInt("mShownAllow", mShownAllow);
}

super.onSaveInstanceState(outState);
Expand Down Expand Up @@ -292,7 +309,7 @@ private void setOptions(int option) {
values.put(Apps.LOGGING, mLoggingEnabled);
break;
}
cr.update(ContentUris.withAppendedId(Apps.CONTENT_URI, mShownIndex),
cr.update(ContentUris.withAppendedId(Apps.CONTENT_URI_UID, mShownUid),
values, null, null);
getSherlockActivity().invalidateOptionsMenu();
}
Expand All @@ -310,7 +327,6 @@ public void toggle(View view) {
} else {
doToggle();
}

}

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

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

ContentValues values = new ContentValues();
values.put(Apps.ALLOW, mAllow == 1?0:1);
cr.update(uri, values, null, null);

// Update the log
values.clear();
values.put(Logs.DATE, System.currentTimeMillis());
values.put(Logs.TYPE, Logs.LogType.TOGGLE);
cr.insert(Uri.withAppendedPath(Logs.CONTENT_URI, String.valueOf(mShownIndex)), values);
Intent intent = new Intent(getActivity(), ResultService.class);
intent.putExtra(ResultService.EXTRA_ACTION, ResultService.ACTION_RECYCLE);
getActivity().startService(intent);
for (Long id : mShownIndexes) {
Uri uri = Uri.withAppendedPath(Apps.CONTENT_URI, String.valueOf(id));
ContentValues values = new ContentValues();
values.put(Apps.ALLOW, mAllow == 1?0:1);
cr.update(uri, values, null, null);

// Update the log
values.clear();
values.put(Logs.DATE, System.currentTimeMillis());
values.put(Logs.TYPE, Logs.LogType.TOGGLE);
cr.insert(Uri.withAppendedPath(Logs.CONTENT_URI, String.valueOf(id)), values);
Intent intent = new Intent(getActivity(), ResultService.class);
intent.putExtra(ResultService.EXTRA_ACTION, ResultService.ACTION_RECYCLE);
getActivity().startService(intent);
}
setShownItem(mShownIndex, mShownUid, mShownAllow == 0?1:0);
}

public void forget(View view) {
Expand All @@ -344,9 +363,10 @@ public void forget(View view) {
}

ContentResolver cr = getActivity().getContentResolver();
Uri uri = Uri.withAppendedPath(Apps.CONTENT_URI, String.valueOf(mShownIndex));

cr.delete(uri, null, null);
for (Long id : mShownIndexes) {
Uri uri = Uri.withAppendedPath(Apps.CONTENT_URI, String.valueOf(id));
cr.delete(uri, null, null);
}
closeDetails();
}

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

@Override
public void clearLog() {
if (mShownIndex != -1) {
getActivity().getContentResolver().delete(ContentUris.withAppendedId(Logs.CONTENT_URI, mShownIndex), null, null);
if (!mShownIndexes.isEmpty()) {
for (Long id : mShownIndexes) {
getActivity().getContentResolver()
.delete(ContentUris.withAppendedId(Logs.CONTENT_URI, id), null, null);
}
}
}

Expand All @@ -380,12 +403,16 @@ public Loader<Cursor> onCreateLoader(int id, Bundle args) {
switch (id) {
case DETAILS_LOADER:
return new CursorLoader(getActivity(),
ContentUris.withAppendedId(Apps.CONTENT_URI, mShownIndex),
DETAILS_PROJECTION, null, null, null);
ContentUris.withAppendedId(Apps.CONTENT_URI_UID, mShownUid),
DETAILS_PROJECTION,
Apps.ALLOW + "=?",
new String[] { String.valueOf(mShownAllow) },
null);
case LOG_LOADER:
return new CursorLoader(getActivity(),
ContentUris.withAppendedId(Logs.CONTENT_URI, mShownIndex),
LogAdapter.PROJECTION, null, null, null);
ContentUris.withAppendedId(Apps.CONTENT_UID_LOGS, mShownUid),
LogAdapter.PROJECTION, Apps.ALLOW + "=?", new String[] { String.valueOf(mShownAllow) },
null);
default:
throw new IllegalArgumentException("Unknown Loader: " + id);
}
Expand Down Expand Up @@ -436,6 +463,15 @@ public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
mNotificationsEnabled = notificationsStr.equals("1")?true:false;
mLoggingEnabled = loggingStr.equals("1")?true:false;
}
StringBuilder commandText = new StringBuilder(data.getString(DETAILS_COLUMN_EXEC_CMD));
mShownIndexes.clear();
mShownIndexes.add(data.getLong(0));
while (data.moveToNext()) {
commandText.append(", ");
commandText.append(data.getString(DETAILS_COLUMN_EXEC_CMD));
mShownIndexes.add(data.getLong(0));
}
mCommandText.setText(commandText.toString());
}
mReady = true;
getSherlockActivity().invalidateOptionsMenu();
Expand Down
9 changes: 7 additions & 2 deletions src/com/noshufou/android/su/AppListFragment.java
Expand Up @@ -108,7 +108,12 @@ public void onResume() {

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
((HomeActivity)getActivity()).showDetails(id);
Cursor c = mAdapter.getCursor();
c.moveToPosition(position);
((HomeActivity)getActivity()).showDetails(
c.getLong(COLUMN_ID),
c.getInt(COLUMN_UID),
c.getInt(COLUMN_ALLOW));
}

private void setupListView() {
Expand All @@ -135,7 +140,7 @@ private void setupListView() {

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

Expand Down
9 changes: 7 additions & 2 deletions src/com/noshufou/android/su/HomeActivity.java
Expand Up @@ -160,15 +160,18 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}

public void showDetails(long id) {
public void showDetails(long id, int uid, int allow) {
if (mDualPane) {
Fragment fragment = getSupportFragmentManager()
.findFragmentById(R.id.fragment_container);
if (fragment instanceof AppDetailsFragment) {
((AppDetailsFragment)fragment).setShownIndex(id);
// ((AppDetailsFragment)fragment).setShownIndex(id);
((AppDetailsFragment)fragment).setShownItem(id, uid, allow);
} else {
Bundle bundle = new Bundle();
bundle.putLong("index", id);
bundle.putInt("uid", uid);
bundle.putInt("allow", allow);
Fragment detailsFragment =
Fragment.instantiate(this, AppDetailsFragment.class.getName(), bundle);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
Expand All @@ -180,6 +183,8 @@ public void showDetails(long id) {
} else {
Intent intent = new Intent(this, AppDetailsActivity.class);
intent.putExtra("index", id);
intent.putExtra("uid", uid);
intent.putExtra("allow", allow);
startActivity(intent);
}
}
Expand Down

0 comments on commit 3aef6ef

Please sign in to comment.