Merge "Recover print job ID from intent extras" into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
61e6b87e7d
@@ -4699,6 +4699,9 @@
|
||||
<!-- Template for the summary of a print job. [CHAR LIMIT=25] -->
|
||||
<string name="print_job_summary"><xliff:g id="printer">%1$s</xliff:g>\n<xliff:g id="time">%2$s</xliff:g></string>
|
||||
|
||||
<!-- Template for the label for a configuring print job (i.e. the user is currently selecting the paper size and printer to use). [CHAR LIMIT=25] -->
|
||||
<string name="print_configuring_state_title_template" >Configuring <xliff:g id="print_job_name" example="foo.jpg">%1$s</xliff:g></string>
|
||||
|
||||
<!-- Template for the label of the state for a ongoing print job. [CHAR LIMIT=25] -->
|
||||
<string name="print_printing_state_title_template">Printing <xliff:g id="print_job_name" example="foo.jpg">%1$s</xliff:g></string>
|
||||
|
||||
|
@@ -28,6 +28,7 @@ import android.print.PrintManager.PrintJobStateChangeListener;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.DateUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@@ -45,6 +46,8 @@ import java.text.DateFormat;
|
||||
* Fragment for management of a print job.
|
||||
*/
|
||||
public class PrintJobSettingsFragment extends SettingsPreferenceFragment {
|
||||
private static final String LOG_TAG = PrintJobSettingsFragment.class.getSimpleName();
|
||||
|
||||
private static final int MENU_ITEM_ID_CANCEL = 1;
|
||||
private static final int MENU_ITEM_ID_RESTART = 2;
|
||||
|
||||
@@ -164,10 +167,17 @@ public class PrintJobSettingsFragment extends SettingsPreferenceFragment {
|
||||
private void processArguments() {
|
||||
String printJobId = getArguments().getString(EXTRA_PRINT_JOB_ID);
|
||||
if (printJobId == null) {
|
||||
finish();
|
||||
} else {
|
||||
mPrintJobId = PrintJobId.unflattenFromString(printJobId);
|
||||
printJobId = getIntent().getStringExtra(EXTRA_PRINT_JOB_ID);
|
||||
|
||||
if (printJobId == null) {
|
||||
Log.w(LOG_TAG, EXTRA_PRINT_JOB_ID + " not set");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mPrintJobId = PrintJobId.unflattenFromString(printJobId);
|
||||
}
|
||||
|
||||
private PrintJob getPrintJob() {
|
||||
@@ -190,6 +200,10 @@ public class PrintJobSettingsFragment extends SettingsPreferenceFragment {
|
||||
PrintJobInfo info = printJob.getInfo();
|
||||
|
||||
switch (info.getState()) {
|
||||
case PrintJobInfo.STATE_CREATED: {
|
||||
mPrintJobPreference.setTitle(getString(
|
||||
R.string.print_configuring_state_title_template, info.getLabel()));
|
||||
} break;
|
||||
case PrintJobInfo.STATE_QUEUED:
|
||||
case PrintJobInfo.STATE_STARTED: {
|
||||
if (!printJob.getInfo().isCancelling()) {
|
||||
|
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.settings.print;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.CancellationSignal;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.print.PageRange;
|
||||
import android.print.PrintAttributes;
|
||||
import android.print.PrintDocumentAdapter;
|
||||
import android.print.PrintDocumentInfo;
|
||||
import android.print.PrintJob;
|
||||
import android.print.PrintManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.filters.LargeTest;
|
||||
import android.support.test.rule.ActivityTestRule;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.support.test.uiautomator.By;
|
||||
import android.support.test.uiautomator.UiDevice;
|
||||
import android.support.test.uiautomator.UiObject2;
|
||||
import android.support.test.uiautomator.Until;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.Settings;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class PrintJobSettingsActivityTest {
|
||||
private static final String EXTRA_PRINT_JOB_ID = "EXTRA_PRINT_JOB_ID";
|
||||
private static final String LOG_TAG = PrintJobSettingsActivityTest.class.getSimpleName();
|
||||
|
||||
// Any activity is fine
|
||||
@Rule
|
||||
public final ActivityTestRule<Settings.PrintSettingsActivity> mActivityRule =
|
||||
new ActivityTestRule<>(Settings.PrintSettingsActivity.class, true);
|
||||
|
||||
public static void runShellCommand(@NonNull String cmd) throws IOException {
|
||||
ParcelFileDescriptor stdOut =
|
||||
InstrumentationRegistry.getInstrumentation().getUiAutomation().executeShellCommand(
|
||||
cmd);
|
||||
|
||||
try (FileInputStream fis = new ParcelFileDescriptor.AutoCloseInputStream(stdOut)) {
|
||||
byte[] buf = new byte[512];
|
||||
while (fis.read(buf) != -1) {
|
||||
// keep reading
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void requirePrintFeature() {
|
||||
assumeTrue(InstrumentationRegistry.getTargetContext().getPackageManager().hasSystemFeature(
|
||||
PackageManager.FEATURE_PRINTING));
|
||||
}
|
||||
|
||||
@Before
|
||||
public void wakeUpScreen() throws Exception {
|
||||
runShellCommand("input keyevent KEYCODE_WAKEUP");
|
||||
}
|
||||
|
||||
@Test
|
||||
@LargeTest
|
||||
public void viewPrintJobSettings() throws Exception {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
Object isWriteCalled = new Object();
|
||||
|
||||
// Create adapter that is good enough to start a print preview
|
||||
PrintDocumentAdapter adapter = new PrintDocumentAdapter() {
|
||||
@Override
|
||||
public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes,
|
||||
CancellationSignal cancellationSignal,
|
||||
LayoutResultCallback callback, Bundle extras) {
|
||||
callback.onLayoutFinished(new PrintDocumentInfo.Builder(uuid.toString()).build(),
|
||||
true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWrite(PageRange[] pages, ParcelFileDescriptor destination,
|
||||
CancellationSignal cancellationSignal,
|
||||
WriteResultCallback callback) {
|
||||
synchronized (isWriteCalled) {
|
||||
isWriteCalled.notify();
|
||||
}
|
||||
callback.onWriteFailed(null);
|
||||
}
|
||||
};
|
||||
|
||||
Activity activity = mActivityRule.getActivity();
|
||||
PrintManager pm = mActivityRule.getActivity().getSystemService(PrintManager.class);
|
||||
|
||||
// Start printing
|
||||
PrintJob printJob = pm.print(uuid.toString(), adapter, null);
|
||||
|
||||
// Wait until print preview is up
|
||||
synchronized (isWriteCalled) {
|
||||
isWriteCalled.wait();
|
||||
}
|
||||
|
||||
// Start print job settings
|
||||
Intent intent = new Intent(android.provider.Settings.ACTION_PRINT_SETTINGS);
|
||||
intent.putExtra(EXTRA_PRINT_JOB_ID, printJob.getId().flattenToString());
|
||||
intent.setData(Uri.fromParts("printjob", printJob.getId().flattenToString(), null));
|
||||
activity.startActivity(intent);
|
||||
|
||||
UiDevice uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
|
||||
UiObject2 printPrefTitle = uiDevice.wait(Until.findObject(By.text("Configuring "
|
||||
+ uuid.toString())), 5000);
|
||||
assertNotNull(printPrefTitle);
|
||||
|
||||
Log.i(LOG_TAG, "Found " + printPrefTitle.getText());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user