Regrant permissions

pull/169/head
M66B 5 years ago
parent db4cec01a9
commit 41ef71b541

@ -129,9 +129,8 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
static final int REQUEST_SOUND = 2;
static final int REQUEST_EXPORT = 3;
static final int REQUEST_IMPORT = 4;
static final int REQUEST_IMPORT_OAUTH = 5;
static final int REQUEST_CHOOSE_ACCOUNT = 6;
static final int REQUEST_DONE = 7;
static final int REQUEST_CHOOSE_ACCOUNT = 5;
static final int REQUEST_DONE = 6;
static final int REQUEST_IMPORT_CERTIFICATE = 7;
static final String ACTION_QUICK_GMAIL = BuildConfig.APPLICATION_ID + ".ACTION_QUICK_GMAIL";
@ -381,9 +380,6 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
if (resultCode == RESULT_OK && data != null)
handleImport(data, this.password);
break;
case REQUEST_IMPORT_OAUTH:
ServiceSynchronize.eval(this, "import/oauth");
break;
case REQUEST_IMPORT_CERTIFICATE:
if (resultCode == RESULT_OK && data != null)
handleImportCertificate(data);
@ -660,14 +656,14 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
args.putParcelable("uri", data.getData());
args.putString("password", password);
new SimpleTask<Boolean>() {
new SimpleTask<Void>() {
@Override
protected void onPreExecute(Bundle args) {
ToastEx.makeText(ActivitySetup.this, R.string.title_executing, Toast.LENGTH_LONG).show();
}
@Override
protected Boolean onExecute(Context context, Bundle args) throws Throwable {
protected Void onExecute(Context context, Bundle args) throws Throwable {
Uri uri = args.getParcelable("uri");
String password = args.getString("password");
@ -676,8 +672,6 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
throw new IllegalArgumentException(context.getString(R.string.title_no_stream));
}
boolean oauth = false;
StringBuilder data = new StringBuilder();
Log.i("Reading URI=" + uri);
ContentResolver resolver = context.getContentResolver();
@ -744,9 +738,6 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
Long aid = account.id;
account.id = null;
if (account.auth_type != MailService.AUTH_TYPE_PASSWORD)
oauth = true;
if (primary != null)
account.primary = false;
@ -992,27 +983,12 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
Log.i("Imported data");
return oauth;
return null;
}
@Override
protected void onExecuted(Bundle args, Boolean oauth) {
protected void onExecuted(Bundle args, Void data) {
ToastEx.makeText(ActivitySetup.this, R.string.title_setup_imported, Toast.LENGTH_LONG).show();
if (oauth && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
List<String> permissions = new ArrayList<>();
permissions.add(Manifest.permission.READ_CONTACTS); // profile
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
permissions.add(Manifest.permission.GET_ACCOUNTS);
for (String permission : permissions)
if (!hasPermission(permission)) {
// TODO: fix permissions request
requestPermissions(permissions.toArray(new String[0]), REQUEST_IMPORT_OAUTH);
//return;
}
}
ServiceSynchronize.eval(ActivitySetup.this, "import");
}

@ -32,6 +32,7 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -60,6 +61,7 @@ public class FragmentAccounts extends FragmentBase {
private ViewGroup view;
private SwipeRefreshLayout swipeRefresh;
private Button btnGrant;
private RecyclerView rvAccount;
private ContentLoadingProgressBar pbWait;
private Group grpReady;
@ -70,6 +72,8 @@ public class FragmentAccounts extends FragmentBase {
private String searching = null;
private AdapterAccount adapter;
private static final int REQUEST_IMPORT_OAUTH = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -91,6 +95,7 @@ public class FragmentAccounts extends FragmentBase {
// Get controls
swipeRefresh = view.findViewById(R.id.swipeRefresh);
btnGrant = view.findViewById(R.id.btnGrant);
rvAccount = view.findViewById(R.id.rvAccount);
pbWait = view.findViewById(R.id.pbWait);
grpReady = view.findViewById(R.id.grpReady);
@ -110,6 +115,13 @@ public class FragmentAccounts extends FragmentBase {
});
swipeRefresh.setEnabled(!settings);
btnGrant.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
requestPermissions(Helper.getOAuthPermissions(), REQUEST_IMPORT_OAUTH);
}
});
rvAccount.setHasFixedSize(false);
LinearLayoutManager llm = new LinearLayoutManager(getContext());
rvAccount.setLayoutManager(llm);
@ -226,6 +238,7 @@ public class FragmentAccounts extends FragmentBase {
fabCompose.show();
}
btnGrant.setVisibility(View.GONE);
grpReady.setVisibility(View.GONE);
pbWait.setVisibility(View.VISIBLE);
@ -255,6 +268,14 @@ public class FragmentAccounts extends FragmentBase {
if (accounts == null)
accounts = new ArrayList<>();
boolean authorized = true;
for (TupleAccountEx account : accounts)
if (account.auth_type != MailService.AUTH_TYPE_PASSWORD &&
!Helper.hasPermissions(getContext(), Helper.getOAuthPermissions())) {
authorized = false;
}
btnGrant.setVisibility(authorized ? View.GONE : View.VISIBLE);
adapter.set(accounts);
pbWait.setVisibility(View.GONE);
@ -298,6 +319,15 @@ public class FragmentAccounts extends FragmentBase {
super.onPrepareOptionsMenu(menu);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == REQUEST_IMPORT_OAUTH)
if (Helper.hasPermissions(getContext(), permissions))
ServiceSynchronize.reload(getContext(), null, "Permissions regranted");
}
private void onSwipeRefresh() {
Bundle args = new Bundle();

@ -15,6 +15,19 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btnGrant"
style="@style/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:minWidth="0dp"
android:minHeight="0dp"
android:tag="disable"
android:text="@string/title_setup_grant_again"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvAccount"
android:layout_width="0dp"
@ -27,7 +40,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toBottomOf="@id/btnGrant" />
<eu.faircode.email.ContentLoadingProgressBar
android:id="@+id/pbWait"

@ -155,6 +155,7 @@
<string name="title_setup_quick_failed">You can try to configure an account and an identity below too</string>
<string name="title_setup_manage">Manage</string>
<string name="title_setup_grant">Grant</string>
<string name="title_setup_grant_again">Grant required permissions</string>
<string name="title_setup_account">Setup accounts</string>
<string name="title_setup_account_remark">To receive email</string>
<string name="title_setup_account_hint">To change color, swipe left/right target folder, etc</string>

Loading…
Cancel
Save