use of com.ichi2.utils.Permissions in project AnkiChinaAndroid by ankichinateam.
the class IntentHandler method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
// Note: This is our entry point from the launcher with intent: android.intent.action.MAIN
Timber.d("onCreate()");
super.onCreate(savedInstanceState);
setContentView(R.layout.progress_bar);
Intent intent = getIntent();
Timber.v(intent.toString());
Intent reloadIntent = new Intent(this, DeckPicker.class);
reloadIntent.setDataAndType(getIntent().getData(), getIntent().getType());
String action = intent.getAction();
// #6157 - We want to block actions that need permissions we don't have, but not the default case
// as this requires nothing
Consumer<Runnable> runIfStoragePermissions = (runnable) -> performActionIfStoragePermission(runnable, reloadIntent, action);
LaunchType launchType = getLaunchType(intent);
switch(launchType) {
case FILE_IMPORT:
runIfStoragePermissions.consume(() -> handleFileImport(intent, reloadIntent, action));
break;
case SYNC:
runIfStoragePermissions.consume(() -> handleSyncIntent(reloadIntent, action));
break;
case REVIEW:
runIfStoragePermissions.consume(() -> handleReviewIntent(intent));
break;
case DEFAULT_START_APP_IF_NEW:
Timber.d("onCreate() performing default action");
launchDeckPickerIfNoOtherTasks(reloadIntent);
break;
default:
Timber.w("Unknown launch type: %s. Performing default action", launchType);
launchDeckPickerIfNoOtherTasks(reloadIntent);
}
}
use of com.ichi2.utils.Permissions in project AnkiChinaAndroid by ankichinateam.
the class MultimediaEditFieldActivity method recreateEditingUi.
private void recreateEditingUi(ChangeUIRequest newUI, @Nullable Bundle savedInstanceState) {
Timber.d("recreateEditingUi()");
// Permissions are checked async, save our current state to allow continuation
mCurrentChangeRequest = newUI;
// As we only get here a second time if we have the required permissions
if (newUI.getRequiresPermissionCheck() && performPermissionRequest(newUI.getField())) {
newUI.markAsPermissionRequested();
return;
}
IControllerFactory controllerFactory = BasicControllerFactory.getInstance(getCol().getTime());
IFieldController fieldController = controllerFactory.createControllerForField(newUI.getField());
if (fieldController == null) {
Timber.w("Field controller creation failed");
UIRecreationHandler.onControllerCreationFailed(newUI, this);
return;
}
UIRecreationHandler.onPreFieldControllerReplacement(mFieldController);
mFieldController = fieldController;
mField = newUI.getField();
setupUIController(mFieldController, savedInstanceState);
LinearLayout linearLayout = findViewById(R.id.LinearLayoutInScrollViewFieldEdit);
linearLayout.removeAllViews();
mFieldController.createUI(this, linearLayout);
UIRecreationHandler.onPostUICreation(newUI, this);
}
use of com.ichi2.utils.Permissions in project AnkiChinaAndroid by ankichinateam.
the class BootService method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
if (sWasRun) {
Timber.d("BootService - Already run");
return;
}
if (!Permissions.hasStorageAccessPermission(context)) {
Timber.w("Boot Service did not execute - no permissions");
return;
}
// There are cases where the app is installed, and we have access, but nothing exist yet
Collection col = getColSafe(context);
if (col == null || col.getDecks() == null) {
Timber.w("Boot Service did not execute - error loading collection");
return;
}
Timber.i("Executing Boot Service");
catchAlarmManagerErrors(context, () -> scheduleDeckReminder(context));
catchAlarmManagerErrors(context, () -> scheduleNotification(col.getTime(), context));
mFailedToShowNotifications = false;
sWasRun = true;
}
use of com.ichi2.utils.Permissions in project Anki-Android by ankidroid.
the class IntentHandler method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
// Note: This is our entry point from the launcher with intent: android.intent.action.MAIN
Timber.d("onCreate()");
super.onCreate(savedInstanceState);
Themes.disableXiaomiForceDarkMode(this);
setContentView(R.layout.progress_bar);
Intent intent = getIntent();
Timber.v(intent.toString());
Intent reloadIntent = new Intent(this, DeckPicker.class);
reloadIntent.setDataAndType(getIntent().getData(), getIntent().getType());
String action = intent.getAction();
// #6157 - We want to block actions that need permissions we don't have, but not the default case
// as this requires nothing
Consumer<Runnable> runIfStoragePermissions = (runnable) -> performActionIfStorageAccessible(runnable, reloadIntent, action);
LaunchType launchType = getLaunchType(intent);
switch(launchType) {
case FILE_IMPORT:
runIfStoragePermissions.accept(() -> handleFileImport(intent, reloadIntent, action));
break;
case SYNC:
runIfStoragePermissions.accept(() -> handleSyncIntent(reloadIntent, action));
break;
case REVIEW:
runIfStoragePermissions.accept(() -> handleReviewIntent(intent));
break;
case DEFAULT_START_APP_IF_NEW:
Timber.d("onCreate() performing default action");
launchDeckPickerIfNoOtherTasks(reloadIntent);
break;
default:
Timber.w("Unknown launch type: %s. Performing default action", launchType);
launchDeckPickerIfNoOtherTasks(reloadIntent);
}
}
use of com.ichi2.utils.Permissions in project Anki-Android by ankidroid.
the class MultimediaEditFieldActivity method recreateEditingUi.
private void recreateEditingUi(ChangeUIRequest newUI, @Nullable Bundle savedInstanceState) {
Timber.d("recreateEditingUi()");
// Permissions are checked async, save our current state to allow continuation
mCurrentChangeRequest = newUI;
// As we only get here a second time if we have the required permissions
if (newUI.getRequiresPermissionCheck() && performPermissionRequest(newUI.getField())) {
newUI.markAsPermissionRequested();
return;
}
IControllerFactory controllerFactory = BasicControllerFactory.getInstance();
IFieldController fieldController = controllerFactory.createControllerForField(newUI.getField());
if (fieldController == null) {
Timber.w("Field controller creation failed");
UIRecreationHandler.onControllerCreationFailed(newUI, this);
return;
}
UIRecreationHandler.onPreFieldControllerReplacement(mFieldController);
mFieldController = fieldController;
mField = newUI.getField();
setupUIController(mFieldController, savedInstanceState);
LinearLayout linearLayout = findViewById(R.id.LinearLayoutInScrollViewFieldEdit);
linearLayout.removeAllViews();
mFieldController.createUI(this, linearLayout);
UIRecreationHandler.onPostUICreation(newUI, this);
}
Aggregations