forked from dotnet/runtime
-
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.
[mono] Implement System.Console for Android (dotnet#35415)
* Implement ConsolePal for Android Co-authored-by: Stephen Toub <[email protected]>
- Loading branch information
1 parent
8c39b7e
commit f283945
Showing
4 changed files
with
222 additions
and
2 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
src/libraries/Common/src/Interop/Android/Interop.Libraries.cs
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,11 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class Libraries | ||
{ | ||
internal const string Liblog = "liblog"; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/libraries/Common/src/Interop/Android/Interop.Logcat.cs
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,31 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class Logcat | ||
{ | ||
[DllImport(Libraries.Liblog)] | ||
private static extern void __android_log_print(LogLevel level, string? tag, string format, string args, IntPtr ptr); | ||
|
||
internal static void AndroidLogPrint(LogLevel level, string? tag, string message) => | ||
__android_log_print(level, tag, "%s", message, IntPtr.Zero); | ||
|
||
internal enum LogLevel | ||
{ | ||
Unknown = 0x00, | ||
Default = 0x01, | ||
Verbose = 0x02, | ||
Debug = 0x03, | ||
Info = 0x04, | ||
Warn = 0x05, | ||
Error = 0x06, | ||
Fatal = 0x07, | ||
Silent = 0x08 | ||
} | ||
} | ||
} |
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
168 changes: 168 additions & 0 deletions
168
src/libraries/System.Console/src/System/ConsolePal.Android.cs
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,168 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.IO; | ||
using System.Text; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace System | ||
{ | ||
internal sealed unsafe class LogcatStream : ConsoleStream | ||
{ | ||
public LogcatStream() : base(FileAccess.Write) {} | ||
|
||
public override int Read(byte[] buffer, int offset, int count) => throw Error.GetReadNotSupported(); | ||
|
||
public override unsafe void Write(byte[] buffer, int offset, int count) | ||
{ | ||
string log = ConsolePal.OutputEncoding.GetString(buffer, offset, count); | ||
Interop.Logcat.AndroidLogPrint(Interop.Logcat.LogLevel.Info, null, log); | ||
} | ||
} | ||
|
||
internal static class ConsolePal | ||
{ | ||
internal static void EnsureConsoleInitialized() { } | ||
|
||
public static Stream OpenStandardInput() => throw new PlatformNotSupportedException(); | ||
|
||
public static Stream OpenStandardOutput() => new LogcatStream(); | ||
|
||
public static Stream OpenStandardError() => new LogcatStream(); | ||
|
||
public static Encoding InputEncoding => throw new PlatformNotSupportedException(); | ||
|
||
public static void SetConsoleInputEncoding(Encoding enc) => throw new PlatformNotSupportedException(); | ||
|
||
public static Encoding OutputEncoding => Encoding.Unicode; | ||
|
||
public static void SetConsoleOutputEncoding(Encoding enc) => throw new PlatformNotSupportedException(); | ||
|
||
public static bool IsInputRedirectedCore() => false; | ||
|
||
public static bool IsOutputRedirectedCore() => false; | ||
|
||
public static bool IsErrorRedirectedCore() => false; | ||
|
||
internal static TextReader GetOrCreateReader() => throw new PlatformNotSupportedException(); | ||
|
||
public static bool NumberLock => false; | ||
|
||
public static bool CapsLock => false; | ||
|
||
public static bool KeyAvailable => false; | ||
|
||
public static ConsoleKeyInfo ReadKey(bool intercept) => throw new PlatformNotSupportedException(); | ||
|
||
public static bool TreatControlCAsInput | ||
{ | ||
get => throw new PlatformNotSupportedException(); | ||
set => throw new PlatformNotSupportedException(); | ||
} | ||
|
||
public static ConsoleColor BackgroundColor | ||
{ | ||
get => throw new PlatformNotSupportedException(); | ||
set => throw new PlatformNotSupportedException(); | ||
} | ||
|
||
public static ConsoleColor ForegroundColor | ||
{ | ||
get => throw new PlatformNotSupportedException(); | ||
set => throw new PlatformNotSupportedException(); | ||
} | ||
|
||
public static void ResetColor() => throw new PlatformNotSupportedException(); | ||
|
||
public static int CursorSize | ||
{ | ||
get => throw new PlatformNotSupportedException(); | ||
set => throw new PlatformNotSupportedException(); | ||
} | ||
|
||
public static bool CursorVisible | ||
{ | ||
get => throw new PlatformNotSupportedException(); | ||
set => throw new PlatformNotSupportedException(); | ||
} | ||
|
||
public static int CursorLeft => throw new PlatformNotSupportedException(); | ||
|
||
public static int CursorTop => throw new PlatformNotSupportedException(); | ||
|
||
public static string Title | ||
{ | ||
get => throw new PlatformNotSupportedException(); | ||
set => throw new PlatformNotSupportedException(); | ||
} | ||
|
||
public static void Beep() => throw new PlatformNotSupportedException(); | ||
|
||
public static void Beep(int frequency, int duration) => throw new PlatformNotSupportedException(); | ||
|
||
public static void MoveBufferArea(int sourceLeft, int sourceTop, | ||
int sourceWidth, int sourceHeight, int targetLeft, int targetTop, | ||
char sourceChar, ConsoleColor sourceForeColor, | ||
ConsoleColor sourceBackColor) => throw new PlatformNotSupportedException(); | ||
|
||
public static void Clear() => throw new PlatformNotSupportedException(); | ||
|
||
public static void SetCursorPosition(int left, int top) => throw new PlatformNotSupportedException(); | ||
|
||
public static int BufferWidth | ||
{ | ||
get => throw new PlatformNotSupportedException(); | ||
set => throw new PlatformNotSupportedException(); | ||
} | ||
|
||
public static int BufferHeight | ||
{ | ||
get => throw new PlatformNotSupportedException(); | ||
set => throw new PlatformNotSupportedException(); | ||
} | ||
|
||
public static void SetBufferSize(int width, int height) => throw new PlatformNotSupportedException(); | ||
|
||
public static int LargestWindowWidth => throw new PlatformNotSupportedException(); | ||
|
||
public static int LargestWindowHeight => throw new PlatformNotSupportedException(); | ||
|
||
public static int WindowLeft | ||
{ | ||
get => throw new PlatformNotSupportedException(); | ||
set => throw new PlatformNotSupportedException(); | ||
} | ||
|
||
public static int WindowTop | ||
{ | ||
get => throw new PlatformNotSupportedException(); | ||
set => throw new PlatformNotSupportedException(); | ||
} | ||
|
||
public static int WindowWidth | ||
{ | ||
get => throw new PlatformNotSupportedException(); | ||
set => throw new PlatformNotSupportedException(); | ||
} | ||
|
||
public static int WindowHeight | ||
{ | ||
get => throw new PlatformNotSupportedException(); | ||
set => throw new PlatformNotSupportedException(); | ||
} | ||
|
||
public static void SetWindowPosition(int left, int top) => throw new PlatformNotSupportedException(); | ||
|
||
public static void SetWindowSize(int width, int height) => throw new PlatformNotSupportedException(); | ||
|
||
internal sealed class ControlCHandlerRegistrar | ||
{ | ||
internal ControlCHandlerRegistrar() => throw new PlatformNotSupportedException(); | ||
|
||
internal void Register() => throw new PlatformNotSupportedException(); | ||
|
||
internal void Unregister() => throw new PlatformNotSupportedException(); | ||
} | ||
} | ||
} |