0
0
Fork 0
mirror of https://github.com/YTVanced/VancedMicroG synced 2025-01-05 15:01:02 +00:00

Add permission self check

This commit is contained in:
Marvin W 2016-03-04 15:54:36 +01:00
parent a65d5dfba8
commit 1e8926edd9
4 changed files with 85 additions and 1 deletions

View file

@ -0,0 +1,76 @@
/*
* Copyright 2013-2016 microG Project Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.microg.tools.selfcheck;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.PermissionGroupInfo;
import android.content.pm.PermissionInfo;
import android.support.v4.app.Fragment;
import android.util.Log;
import org.microg.tools.ui.R;
import static android.os.Build.VERSION_CODES.M;
import static org.microg.tools.selfcheck.SelfCheckGroup.Result.Negative;
import static org.microg.tools.selfcheck.SelfCheckGroup.Result.Positive;
@TargetApi(M)
public class PermissionCheckGroup implements SelfCheckGroup {
private static final String TAG = "SelfCheckPerms";
private String[] permissions;
public PermissionCheckGroup(String... permissions) {
this.permissions = permissions;
}
@Override
public String getGroupName(Context context) {
return context.getString(R.string.self_check_cat_permissions);
}
@Override
public void doChecks(Context context, ResultCollector collector) {
for (String permission : permissions) {
doPermissionCheck(context, collector, permission);
}
}
private void doPermissionCheck(Context context, ResultCollector collector, final String permission) {
PackageManager pm = context.getPackageManager();
try {
PermissionInfo info = pm.getPermissionInfo(permission, 0);
PermissionGroupInfo groupInfo = info.group != null ? pm.getPermissionGroupInfo(info.group, 0) : null;
CharSequence permLabel = info.loadLabel(pm);
CharSequence groupLabel = groupInfo != null ? groupInfo.loadLabel(pm) : permLabel;
collector.addResult(context.getString(R.string.self_check_name_permission, permLabel),
context.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED ? Positive : Negative,
context.getString(R.string.self_check_resolution_permission, groupLabel),
new SelfCheckGroup.CheckResolver() {
@Override
public void tryResolve(Fragment fragment) {
fragment.requestPermissions(new String[]{permission}, 0);
}
});
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, e);
}
}
}

View file

@ -65,7 +65,7 @@
android:paddingRight="?attr/listPreferredItemPaddingRight"
android:paddingTop="16dip"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:text="@+id/about_root_libraries"
android:text="@string/about_root_libraries"
android:textColor="?attr/colorAccent"/>
<ListView

View file

@ -20,4 +20,8 @@
<string name="self_check_title">микроГ самопровера</string>
<string name="self_check_desc">Провера исправности подешавања система за коришћење микроГ услуга.</string>
<string name="self_check_cat_permissions">Дозволе одобрене</string>
<string name="self_check_name_permission">Дозволе за %1$s:</string>
<string name="self_check_resolution_permission">Тапните овде да одобрите дозволе за %1$s. Не одобравање дозвола може да резултира чудним понашањем апликација.</string>
</resources>

View file

@ -28,6 +28,10 @@
<string name="self_check_title">Self-Check</string>
<string name="self_check_desc">Check if the system is correctly set up to use microG.</string>
<string name="self_check_cat_permissions">Permissions granted</string>
<string name="self_check_name_permission">Permission to %1$s:</string>
<string name="self_check_resolution_permission">Touch here to grant permission to %1$s. Not granting the permission can result in misbehaving applications.</string>
<string name="about_root_title">microG UI Demo</string>
<string name="about_root_summary">Summary</string>
<string name="about_root_version">Version v0.1.0</string>