Removed storage permission, it is not necessary

This commit is contained in:
PeratX 2017-05-21 16:59:01 +08:00
parent b94ed4f5eb
commit fff3e6e1af
5 changed files with 2 additions and 56 deletions

View File

@ -5,8 +5,8 @@
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/> <uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> android:maxSdkVersion="18"/>
<application <application
android:name=".Daedalus" android:name=".Daedalus"

View File

@ -1,19 +1,16 @@
package org.itxtech.daedalus; package org.itxtech.daedalus;
import android.Manifest;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.Application; import android.app.Application;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ShortcutInfo; import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager; import android.content.pm.ShortcutManager;
import android.graphics.drawable.Icon; import android.graphics.drawable.Icon;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v4.app.ActivityCompat;
import android.util.Log; import android.util.Log;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
@ -129,24 +126,8 @@ public class Daedalus extends Application {
return gson.fromJson(reader, beanClass); return gson.fromJson(reader, beanClass);
} }
public static final int REQUEST_EXTERNAL_STORAGE = 1;
public static final String[] PERMISSIONS_STORAGE = {
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
};
public static void initHostsResolver() { public static void initHostsResolver() {
if (Daedalus.getPrefs().getBoolean("settings_local_rules_resolution", false)) { if (Daedalus.getPrefs().getBoolean("settings_local_rules_resolution", false)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int permission = ActivityCompat.checkSelfPermission(Daedalus.getInstance(), Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (MainActivity.getInstance() != null) {
if (permission != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.getInstance(), PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE);
}
} else if (permission != PackageManager.PERMISSION_GRANTED) {
return;
}
}
ArrayList<String> pendingLoad = new ArrayList<>(); ArrayList<String> pendingLoad = new ArrayList<>();
int type = Rule.TYPE_HOSTS; int type = Rule.TYPE_HOSTS;
for (Rule rule : configurations.getRules()) { for (Rule rule : configurations.getRules()) {

View File

@ -1,18 +1,13 @@
package org.itxtech.daedalus.activity; package org.itxtech.daedalus.activity;
import android.Manifest;
import android.app.FragmentManager; import android.app.FragmentManager;
import android.app.FragmentTransaction; import android.app.FragmentTransaction;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView; import android.support.design.widget.NavigationView;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v4.view.GravityCompat; import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.ActionBarDrawerToggle;
@ -106,39 +101,12 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
Log.d(TAG, "onCreate"); Log.d(TAG, "onCreate");
} }
private void checkStorage() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int permission = ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permission != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, Daedalus.PERMISSIONS_STORAGE, Daedalus.REQUEST_EXTERNAL_STORAGE);
}
}
getExternalFilesDir(null);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
case Daedalus.REQUEST_EXTERNAL_STORAGE:
if (grantResults[0] != PackageManager.PERMISSION_GRANTED) {
Snackbar.make(findViewById(R.id.id_content), R.string.notice_need_storage_perm, Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
break;
default:
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
@Override @Override
public void onPostCreate(Bundle savedInstanceState) { public void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState); super.onPostCreate(savedInstanceState);
updateTitle(); updateTitle();
updateNavigationMenu(); updateNavigationMenu();
checkStorage();
} }
private void updateNavigationMenu() { private void updateNavigationMenu() {

View File

@ -45,7 +45,6 @@
<string name="settings_advanced_on">开启</string> <string name="settings_advanced_on">开启</string>
<string name="settings_local_rules_resolution">本地规则解析</string> <string name="settings_local_rules_resolution">本地规则解析</string>
<string name="notice_need_restart">重新启用 Daedalus 以应用设置。</string> <string name="notice_need_restart">重新启用 Daedalus 以应用设置。</string>
<string name="notice_need_storage_perm">Daedalus 需要访问外部储存以实现本地规则解析。</string>
<string name="action_rules">规则</string> <string name="action_rules">规则</string>
<string name="button_text_download_hosts">下载 hosts</string> <string name="button_text_download_hosts">下载 hosts</string>
<string name="notice_start_download">正在下载规则,请稍等 ……</string> <string name="notice_start_download">正在下载规则,请稍等 ……</string>

View File

@ -44,8 +44,6 @@
<string name="settings_advanced_on">On</string> <string name="settings_advanced_on">On</string>
<string name="settings_local_rules_resolution">Local hosts resolution</string> <string name="settings_local_rules_resolution">Local hosts resolution</string>
<string name="notice_need_restart">Re-activate Daedalus to make the settings take effect.</string> <string name="notice_need_restart">Re-activate Daedalus to make the settings take effect.</string>
<string name="notice_need_storage_perm">Daedalus requires access to external storage for local rules resolution.
</string>
<string name="action_rules">Rules</string> <string name="action_rules">Rules</string>
<string name="button_text_download_hosts">Download hosts</string> <string name="button_text_download_hosts">Download hosts</string>
<string name="notice_start_download">Downloading rule, please wait …</string> <string name="notice_start_download">Downloading rule, please wait …</string>