forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Chromecast] Added AIDL to get assistant device logs
Bug: 71798364 Bug: 71646628 Test: Send feedback on home app Change-Id: Iba23a4e07369a9557a8ef43c23a7f93f3184a9c6 Reviewed-on: https://chromium-review.googlesource.com/882493 Commit-Queue: Sandeep Vijayasekar <sandv@chromium.org> Reviewed-by: Robert Sesek <rsesek@chromium.org> Reviewed-by: Luke Halliwell <halliwell@chromium.org> Reviewed-by: Stephen Lanham <slan@chromium.org> Cr-Commit-Position: refs/heads/master@{#531793}
- Loading branch information
Sandeep Vijayasekar
authored and
Commit Bot
committed
Jan 25, 2018
1 parent
a6edf46
commit 4ddbad7
Showing
14 changed files
with
334 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...ecast/browser/android/apk/src/org/chromium/chromecast/shell/AndroidAppLogcatProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package org.chromium.chromecast.shell; | ||
|
||
import org.chromium.base.Log; | ||
import org.chromium.chromecast.base.CircularBuffer; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.nio.charset.Charset; | ||
import java.nio.charset.UnsupportedCharsetException; | ||
|
||
/** | ||
* Extracts logcat out of Android devices and elide PII sensitive info from it. | ||
* | ||
* <p>Elided information includes: Emails, IP address, MAC address, URL/domains as well as | ||
* Javascript console messages. | ||
*/ | ||
class AndroidAppLogcatProvider extends ElidedLogcatProvider { | ||
private static final String TAG = "LogcatProvider"; | ||
private static final long HALF_SECOND = 500; | ||
|
||
@Override | ||
protected void getRawLogcat(RawLogcatCallback callback) { | ||
CircularBuffer<String> rawLogcat = new CircularBuffer<>(BuildConfig.LOGCAT_SIZE); | ||
String logLn = null; | ||
Integer exitValue = null; | ||
|
||
try { | ||
Process p = Runtime.getRuntime().exec("logcat -d"); | ||
try (BufferedReader bReader = new BufferedReader( | ||
new InputStreamReader(p.getInputStream(), Charset.forName("UTF-8")))) { | ||
while (exitValue == null) { | ||
while ((logLn = bReader.readLine()) != null) { | ||
// Add each new string to the end of the buffer. | ||
rawLogcat.add(logLn); | ||
} | ||
try { | ||
exitValue = p.exitValue(); | ||
} catch (IllegalThreadStateException itse) { | ||
Thread.sleep(HALF_SECOND); | ||
} | ||
} | ||
if (exitValue != 0) { | ||
String msg = "Logcat process exit value: " + exitValue; | ||
Log.w(TAG, msg); | ||
} | ||
} catch (UnsupportedCharsetException e) { | ||
// Should never happen; all Java implementations are required to support UTF-8. | ||
Log.wtf(TAG, "UTF-8 not supported", e); | ||
} catch (InterruptedException e) { | ||
Log.e(TAG, "Logcat subprocess interrupted ", e); | ||
} | ||
} catch (IOException e) { | ||
Log.e(TAG, "Error occurred trying to upload crash dump", e); | ||
} finally { | ||
callback.onLogsDone(rawLogcat); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
chromecast/browser/android/apk/src/org/chromium/chromecast/shell/DumpStreamUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package org.chromium.chromecast.shell; | ||
|
||
import org.chromium.base.Log; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.nio.charset.Charset; | ||
import java.nio.charset.UnsupportedCharsetException; | ||
|
||
/** | ||
* Utility class for dump streams | ||
* | ||
*/ | ||
public final class DumpStreamUtils { | ||
private static final String TAG = "cr_DumpStreamUtils"; | ||
|
||
/** | ||
* Gets the first line from an input stream | ||
* Mutates given input stream. | ||
* | ||
* @return First line of the input stream. | ||
* @throws IOException | ||
*/ | ||
public static String getFirstLineFromStream(InputStream inputStream) throws IOException { | ||
try (InputStreamReader streamReader = | ||
new InputStreamReader(inputStream, Charset.forName("UTF-8")); | ||
BufferedReader reader = new BufferedReader(streamReader)) { | ||
return reader.readLine(); | ||
} catch (UnsupportedCharsetException e) { | ||
// Should never happen; all Java implementations are required to support UTF-8. | ||
Log.wtf(TAG, "UTF-8 not supported", e); | ||
return ""; | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
chromecast/browser/android/apk/src/org/chromium/chromecast/shell/ElidedLogcatProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package org.chromium.chromecast.shell; | ||
|
||
import org.chromium.base.VisibleForTesting; | ||
|
||
/** | ||
* Extracts logcat out of Android devices and elide PII sensitive info from it. | ||
* | ||
* <p>Elided information includes: Emails, IP address, MAC address, URL/domains as well as | ||
* Javascript console messages. | ||
*/ | ||
abstract class ElidedLogcatProvider { | ||
protected abstract void getRawLogcat(RawLogcatCallback rawLogcatCallback); | ||
|
||
protected interface RawLogcatCallback { public void onLogsDone(Iterable<String> logs); } | ||
public interface LogcatCallback { public void onLogsDone(String logs); } | ||
|
||
public void getElidedLogcat(LogcatCallback callback) { | ||
getRawLogcat((Iterable<String> rawLogs) -> callback.onLogsDone(elideLogcat(rawLogs))); | ||
} | ||
|
||
@VisibleForTesting | ||
protected static String elideLogcat(Iterable<String> rawLogcat) { | ||
StringBuilder builder = new StringBuilder(); | ||
for (String line : rawLogcat) { | ||
builder.append(LogcatElision.elide(line)); | ||
builder.append("\n"); | ||
} | ||
return builder.toString(); | ||
} | ||
} |
Oops, something went wrong.