Search in sources :

Example 1 with Permissions

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);
    }
}
Also used : Bundle(android.os.Bundle) Consumer(com.ichi2.utils.FunctionalInterfaces.Consumer) CheckResult(androidx.annotation.CheckResult) NonNull(androidx.annotation.NonNull) Intent(android.content.Intent) DialogHandler(com.ichi2.anki.dialogs.DialogHandler) ReminderService(com.ichi2.anki.services.ReminderService) Permissions(com.ichi2.utils.Permissions) Timber(timber.log.Timber) Message(android.os.Message) ImportUtils(com.ichi2.utils.ImportUtils) ImportResult(com.ichi2.utils.ImportUtils.ImportResult) Activity(android.app.Activity) VisibleForTesting(androidx.annotation.VisibleForTesting) Intent(android.content.Intent)

Example 2 with Permissions

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);
}
Also used : IControllerFactory(com.ichi2.anki.multimediacard.fields.IControllerFactory) IFieldController(com.ichi2.anki.multimediacard.fields.IFieldController) LinearLayout(android.widget.LinearLayout)

Example 3 with Permissions

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;
}
Also used : Collection(com.ichi2.libanki.Collection)

Example 4 with Permissions

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);
    }
}
Also used : Bundle(android.os.Bundle) CheckResult(androidx.annotation.CheckResult) NonNull(androidx.annotation.NonNull) Intent(android.content.Intent) DialogHandler(com.ichi2.anki.dialogs.DialogHandler) ReminderService(com.ichi2.anki.services.ReminderService) Themes(com.ichi2.themes.Themes) Permissions(com.ichi2.utils.Permissions) Timber(timber.log.Timber) Consumer(java.util.function.Consumer) Message(android.os.Message) ImportUtils(com.ichi2.utils.ImportUtils) Build(android.os.Build) ImportResult(com.ichi2.utils.ImportUtils.ImportResult) Activity(android.app.Activity) VisibleForTesting(androidx.annotation.VisibleForTesting) Intent(android.content.Intent)

Example 5 with Permissions

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);
}
Also used : IControllerFactory(com.ichi2.anki.multimediacard.fields.IControllerFactory) IFieldController(com.ichi2.anki.multimediacard.fields.IFieldController) LinearLayout(android.widget.LinearLayout)

Aggregations

Activity (android.app.Activity)2 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 Message (android.os.Message)2 LinearLayout (android.widget.LinearLayout)2 CheckResult (androidx.annotation.CheckResult)2 NonNull (androidx.annotation.NonNull)2 VisibleForTesting (androidx.annotation.VisibleForTesting)2 DialogHandler (com.ichi2.anki.dialogs.DialogHandler)2 IControllerFactory (com.ichi2.anki.multimediacard.fields.IControllerFactory)2 IFieldController (com.ichi2.anki.multimediacard.fields.IFieldController)2 ReminderService (com.ichi2.anki.services.ReminderService)2 ImportUtils (com.ichi2.utils.ImportUtils)2 ImportResult (com.ichi2.utils.ImportUtils.ImportResult)2 Permissions (com.ichi2.utils.Permissions)2 Timber (timber.log.Timber)2 Build (android.os.Build)1 Collection (com.ichi2.libanki.Collection)1 Themes (com.ichi2.themes.Themes)1 Consumer (com.ichi2.utils.FunctionalInterfaces.Consumer)1