Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions activity/activity/src/androidTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<activity android:name="androidx.activity.LifecycleComponentActivity"/>
<activity android:name="androidx.activity.EagerOverrideLifecycleComponentActivity"/>
<activity android:name="androidx.activity.LazyOverrideLifecycleComponentActivity"/>
<activity android:name="androidx.activity.ReportFullyDrawnActivity"/>
<activity android:name="androidx.activity.ViewModelActivity"/>
<activity android:name="androidx.activity.SavedStateActivity"/>
<activity android:name="androidx.activity.ContentViewActivity"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2020 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 androidx.activity

import androidx.test.core.app.ActivityScenario
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import androidx.testutils.withActivity
import org.junit.Test
import org.junit.runner.RunWith

@LargeTest
@RunWith(AndroidJUnit4::class)
class ComponentActivityReportFullyDrawnTest {

@Test
fun testReportFullyDrawn() {
with(ActivityScenario.launch(ReportFullyDrawnActivity::class.java)) {
withActivity {
// This test makes sure that this method does not throw an exception on devices
// running API 19 (without UPDATE_DEVICE_STATS permission) and earlier
// (regardless or permissions).
reportFullyDrawn()
}
}
}
}

class ReportFullyDrawnActivity : ComponentActivity()
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static androidx.activity.result.contract.ActivityResultContracts.StartIntentSenderForResult.EXTRA_INTENT_SENDER_REQUEST;
import static androidx.activity.result.contract.ActivityResultContracts.StartIntentSenderForResult.EXTRA_SEND_INTENT_EXCEPTION;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
Expand Down Expand Up @@ -62,6 +63,7 @@
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
import androidx.core.app.ActivityOptionsCompat;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.HasDefaultViewModelProviderFactory;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleEventObserver;
Expand Down Expand Up @@ -685,4 +687,19 @@ public final <I, O> ActivityResultLauncher<I> registerForActivityResult(
public final ActivityResultRegistry getActivityResultRegistry() {
return mActivityResultRegistry;
}

@Override
public void reportFullyDrawn() {
if (Build.VERSION.SDK_INT > 19) {
super.reportFullyDrawn();
} else if (Build.VERSION.SDK_INT == 19 && ContextCompat.checkSelfPermission(this,
Manifest.permission.UPDATE_DEVICE_STATS) == PackageManager.PERMISSION_GRANTED) {
// On API 19, the Activity.reportFullyDrawn() method requires the UPDATE_DEVICE_STATS
// permission, otherwise it throws an exception. Instead of throwing, we fall back to
// a no-op call.
super.reportFullyDrawn();
}
// The Activity.reportFullyDrawn() got added in API 19, fall back to a no-op call if this
// method gets called on devices with an earlier version.
}
}