Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d7a61a7d authored by Sumedh Sen's avatar Sumedh Sen
Browse files

Introduce UninstallRepository and UninstallViewModel

This change introduces the repository, viewmodel and viewmodel factory and links the view to the viewmodel.

Bug: 182205982
Test: builds successfully
Test: No CTS Tests. Flag to use new app is turned off by default

Change-Id: Id5d98c7f7ca0c4b1d71053b3b3dce3338f96cfcf
parent 24c007b3
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * 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
 *
 *      https://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 com.android.packageinstaller.v2.model;

import android.content.Context;

public class UninstallRepository {

    private static final String TAG = UninstallRepository.class.getSimpleName();
    private final Context mContext;

    public UninstallRepository(Context context) {
        mContext = context;
    }
}
+12 −0
Original line number Diff line number Diff line
@@ -21,6 +21,10 @@ import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTE
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.ViewModelProvider;
import com.android.packageinstaller.v2.model.UninstallRepository;
import com.android.packageinstaller.v2.viewmodel.UninstallViewModel;
import com.android.packageinstaller.v2.viewmodel.UninstallViewModelFactory;

public class UninstallLaunch extends FragmentActivity{

@@ -30,6 +34,9 @@ public class UninstallLaunch extends FragmentActivity{
        UninstallLaunch.class.getPackageName() + ".callingActivityName";
    public static final String TAG = UninstallLaunch.class.getSimpleName();

    private UninstallViewModel mUninstallViewModel;
    private UninstallRepository mUninstallRepository;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        getWindow().addSystemFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
@@ -37,5 +44,10 @@ public class UninstallLaunch extends FragmentActivity{
        // Never restore any state, esp. never create any fragments. The data in the fragment might
        // be stale, if e.g. the app was uninstalled while the activity was destroyed.
        super.onCreate(null);

        mUninstallRepository = new UninstallRepository(getApplicationContext());
        mUninstallViewModel = new ViewModelProvider(this,
            new UninstallViewModelFactory(this.getApplication(), mUninstallRepository)).get(
            UninstallViewModel.class);
    }
}
+33 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * 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
 *
 *      https://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 com.android.packageinstaller.v2.viewmodel;

import android.app.Application;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import com.android.packageinstaller.v2.model.UninstallRepository;

public class UninstallViewModel extends AndroidViewModel {

    private static final String TAG = UninstallViewModel.class.getSimpleName();
    private final UninstallRepository mRepository;

    public UninstallViewModel(@NonNull Application application, UninstallRepository repository) {
        super(application);
        mRepository = repository;
    }
}
+46 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * 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 com.android.packageinstaller.v2.viewmodel;

import android.app.Application;
import androidx.annotation.NonNull;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;
import com.android.packageinstaller.v2.model.UninstallRepository;

public class UninstallViewModelFactory extends ViewModelProvider.AndroidViewModelFactory {

    private final UninstallRepository mRepository;
    private final Application mApplication;

    public UninstallViewModelFactory(Application application, UninstallRepository repository) {
        // Calling super class' ctor ensures that create method is called correctly and the right
        // ctor of UninstallViewModel is used. If we fail to do that, the default ctor:
        // UninstallViewModel(application) is used, and repository isn't initialized in
        // the viewmodel
        super(application);
        mApplication = application;
        mRepository = repository;
    }

    @NonNull
    @Override
    @SuppressWarnings("unchecked")
    public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
        return (T) new UninstallViewModel(mApplication, mRepository);
    }
}