From 7043627a3a7af5eabac3ab11859b6196b814a8fb Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Mon, 25 Jun 2018 23:18:01 +0200 Subject: [PATCH] basic Install History viewer, available only when logging is enabled This provides a super simple way to view the install history directly in F-Droid. --- app/src/basic/res/xml/preferences.xml | 10 ++ app/src/main/AndroidManifest.xml | 6 ++ .../installer/InstallHistoryService.java | 5 +- .../fdroid/views/InstallHistoryActivity.java | 92 +++++++++++++++++++ .../views/fragments/PreferencesFragment.java | 3 + .../res/layout/activity_install_history.xml | 40 ++++++++ app/src/main/res/menu/install_history.xml | 7 ++ app/src/main/res/values/strings.xml | 2 + app/src/main/res/xml/preferences.xml | 10 ++ 9 files changed, 173 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/org/fdroid/fdroid/views/InstallHistoryActivity.java create mode 100644 app/src/main/res/layout/activity_install_history.xml create mode 100644 app/src/main/res/menu/install_history.xml diff --git a/app/src/basic/res/xml/preferences.xml b/app/src/basic/res/xml/preferences.xml index 026a8ed0c..8b249dae8 100644 --- a/app/src/basic/res/xml/preferences.xml +++ b/app/src/basic/res/xml/preferences.xml @@ -24,6 +24,16 @@ android:targetPackage="@string/applicationId" android:targetClass="org.fdroid.fdroid.views.ManageReposActivity"/> + + + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 457f02c1e..bff6cbc32 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -550,6 +550,12 @@ android:name="android.support.PARENT_ACTIVITY" android:value=".views.main.MainActivity"/> + + + diff --git a/app/src/main/java/org/fdroid/fdroid/installer/InstallHistoryService.java b/app/src/main/java/org/fdroid/fdroid/installer/InstallHistoryService.java index 6d930c850..7c280c8db 100644 --- a/app/src/main/java/org/fdroid/fdroid/installer/InstallHistoryService.java +++ b/app/src/main/java/org/fdroid/fdroid/installer/InstallHistoryService.java @@ -28,7 +28,7 @@ import android.net.Uri; import android.os.Process; import android.support.v4.content.LocalBroadcastManager; import android.text.TextUtils; - +import org.fdroid.fdroid.BuildConfig; import org.fdroid.fdroid.Utils; import org.fdroid.fdroid.data.Apk; @@ -47,7 +47,8 @@ import java.util.List; public class InstallHistoryService extends IntentService { public static final String TAG = "InstallHistoryService"; - public static final Uri LOG_URI = Uri.parse("content://org.fdroid.fdroid.installer/install_history/all"); + public static final String AUTHORITY = BuildConfig.APPLICATION_ID + ".installer"; + public static final Uri LOG_URI = Uri.parse("content://" + AUTHORITY + "/install_history/all"); private static BroadcastReceiver broadcastReceiver; diff --git a/app/src/main/java/org/fdroid/fdroid/views/InstallHistoryActivity.java b/app/src/main/java/org/fdroid/fdroid/views/InstallHistoryActivity.java new file mode 100644 index 000000000..6d550baa1 --- /dev/null +++ b/app/src/main/java/org/fdroid/fdroid/views/InstallHistoryActivity.java @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2016 Blue Jay Wireless + * Copyright (C) 2018 Senecto Limited + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 3 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +package org.fdroid.fdroid.views; + +import android.content.ContentResolver; +import android.database.Cursor; +import android.os.Bundle; +import android.os.ParcelFileDescriptor; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.Menu; +import android.view.MenuItem; +import android.widget.TextView; +import org.apache.commons.io.IOUtils; +import org.fdroid.fdroid.R; +import org.fdroid.fdroid.installer.InstallHistoryService; + +import java.io.FileDescriptor; +import java.io.FileInputStream; +import java.io.IOException; +import java.nio.charset.Charset; + +public class InstallHistoryActivity extends AppCompatActivity { + public static final String TAG = "InstallHistoryActivity"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_install_history); + Toolbar toolbar = findViewById(R.id.toolbar); + toolbar.setTitle(getString(R.string.install_history)); + setSupportActionBar(toolbar); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + + String text = ""; + try { + ContentResolver resolver = getContentResolver(); + + Cursor cursor = resolver.query(InstallHistoryService.LOG_URI, null, null, null, null); + if (cursor != null) { + cursor.moveToFirst(); + cursor.close(); + } + + ParcelFileDescriptor pfd = resolver.openFileDescriptor(InstallHistoryService.LOG_URI, "r"); + FileDescriptor fd = pfd.getFileDescriptor(); + FileInputStream fileInputStream = new FileInputStream(fd); + text = IOUtils.toString(fileInputStream, Charset.defaultCharset()); + } catch (IOException | SecurityException | IllegalStateException e) { + e.printStackTrace(); + } + TextView textView = findViewById(R.id.text); + textView.setText(text); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.install_history, menu); + return super.onCreateOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + + switch (item.getItemId()) { + case R.id.menu_delete: + getContentResolver().delete(InstallHistoryService.LOG_URI, null, null); + TextView textView = findViewById(R.id.text); + textView.setText(""); + break; + } + return super.onOptionsItemSelected(item); + } +} diff --git a/app/src/main/java/org/fdroid/fdroid/views/fragments/PreferencesFragment.java b/app/src/main/java/org/fdroid/fdroid/views/fragments/PreferencesFragment.java index 29ddebce6..8c49f0617 100644 --- a/app/src/main/java/org/fdroid/fdroid/views/fragments/PreferencesFragment.java +++ b/app/src/main/java/org/fdroid/fdroid/views/fragments/PreferencesFragment.java @@ -337,10 +337,13 @@ public class PreferencesFragment extends PreferenceFragment case Preferences.PREF_KEEP_INSTALL_HISTORY: CheckBoxPreference p = (CheckBoxPreference) findPreference(key); + Preference installHistory = findPreference("installHistory"); if (p.isChecked()) { InstallHistoryService.register(getActivity()); + installHistory.setVisible(true); } else { InstallHistoryService.unregister(getActivity()); + installHistory.setVisible(false); } break; } diff --git a/app/src/main/res/layout/activity_install_history.xml b/app/src/main/res/layout/activity_install_history.xml new file mode 100644 index 000000000..38adba30f --- /dev/null +++ b/app/src/main/res/layout/activity_install_history.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/menu/install_history.xml b/app/src/main/res/menu/install_history.xml new file mode 100644 index 000000000..7dd18dbb9 --- /dev/null +++ b/app/src/main/res/menu/install_history.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f5a44f9c7..f16836e0c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -24,6 +24,8 @@ Prevent all actions from showing in the status bar and notification drawer. + Install history + View the private log of all installs and uninstalls Keep install history Store a log of all installs and uninstalls in a private store Send version and UUID to servers diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 2a9309d09..8d49dc77b 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -24,6 +24,16 @@ android:targetPackage="@string/applicationId" android:targetClass="org.fdroid.fdroid.views.ManageReposActivity"/> + + +